Page 1 of 1

[mostly fixed]Jump CollisionAnimator

Posted: Sat Apr 04, 2009 7:42 pm
by Squarefox2
Hello,

Code: Select all

 
// Jump & move
if (mo_emgr->KeyPressed(irr::EKEY_CODE::KEY_SPACE) && !AnimatorSpringen->isFalling() && (Player->getPosition().Y <= 0.1))
        AnimatorSpringen->jump(0.2f); // Jumping
 
jumps higher at higher Framerate (40Fps ~ 2times, 80Fps ~ 3times).

Greetings,
Squarefox

Posted: Sun Apr 05, 2009 2:14 am
by hayate
I don't know Jump CollisionAnimator or your full code but maybe it isn't a bug.
Are you sure the code you wrote isn't frame rate dependant?
Something like: your posted code is in the main loop and it adds power to the jump for every frame, more frames--->more "jump power"

Try to multiply the value with the delta time and see if the problem is solved, if not then wait for a more useful help :wink:

Posted: Sun Apr 05, 2009 11:01 am
by Squarefox2
I only call this jump one time, so there are no multiple jumps.

Posted: Sun Apr 05, 2009 6:47 pm
by hybrid
The question is if your movement code is framerate dependent, because the jump() only influences your movement calculations.

Posted: Mon Apr 06, 2009 12:11 am
by hayate
Squarefox2 wrote:I only call this jump one time, so there are no multiple jumps.
I didn't explain myself properly, I'm not talkin about the number of times you call it, I'm talking about how you call it:

If the code is written this way the node will be moved by 1 on the X axis for every frame of the program, so more frames means more speed

Code: Select all

  // MAIN LOOP
  while( device->run() && device )
  {
    ... //other code

         //// Framerate dependant movement ////
    node->setPosition( node->getPosition() + vector3df(1,0,0)  );

    ... //other code
  }
If the code is written multipling the values with the length of the frame then more frames per second means shorter frames that means less movement per frame and (with little math skills) you can see that the movement speed became constant even with differents FPS

Code: Select all

  timer = device->getTimer() ;
  lastTime = timer->getTime() ;

  // MAIN LOOP
  while( device->run() && device )
  {
    //Retrieving Data from timer
    newTime = timer->getTime() ;
    deltaTime = newTime-lastTime ;
    lastTime = newTime ;

   ... //other code

       //// Not framerate dependant movement (note the "* deltaTime")////
    node->setPosition( node->getPosition() + ( vector3df(1,0,0) * deltaTime ) / 1000); // "/1000" is needed because deltaTime is in ms

   ... //other code
  }
I only thougth your problem is that "AnimatorSpringen->jump(0.2f);" may fall in my first example as it usually causes problems like the ones you described in your first post :)

Posted: Mon Apr 06, 2009 12:50 am
by Squarefox2
I'm using an Irrlicht collision response animator for my node. For this animator I call the Irrlicht predefined function jump().
There is no way to use any delta-time, cause the collision response animator is doing all the calculation.

Maybe the actual implementation is framedependend, which would be not so useful.
It would make more sense if the collision response animator would be doing frameindependent calculations.

Re: Jump CollisionAnimator

Posted: Sat Aug 09, 2014 3:57 pm
by JLouisB
Up, this bug is still in Irrlicht (also reported here)

My little patch to fix this problem :

Code: Select all

Index: CSceneNodeAnimatorCollisionResponse.cpp
===================================================================
--- CSceneNodeAnimatorCollisionResponse.cpp (revision 4908)
+++ CSceneNodeAnimatorCollisionResponse.cpp (working copy)
@@ -189,7 +189,8 @@
            = SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
                World, LastPosition-Translation,
                Radius, vel, CollisionTriangle, CollisionPoint, f,
-               CollisionNode, SlidingSpeed, FallingVelocity);
+               CollisionNode, SlidingSpeed, FallingVelocity * (f32)diff * 0.2f);
+        // FallingVelocity is multiplied by 0.2f instead of 0.001f simply because with this value, gravity and jump value don't have to be changed in the Irrlicht examples + demo (Otherwise the solution is to change jump/gravity value in demo, examples 7 and 21).
 
        CollisionOccurred = (CollisionTriangle != RefTriangle);
 
Package with patch, test case application and comments :
https://dl.dropboxusercontent.com/u/244 ... endant.zip

Can you fix this bug for a next release please ?
Thanks

Re: Jump CollisionAnimator

Posted: Tue Sep 02, 2014 11:13 am
by JLouisB
I have also find a bug with CSceneNodeAnimatorCollisionResponse::createClone, line 271 :

CSceneNodeAnimatorCollisionResponse * newAnimator =
new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius,
(Gravity * 1000.0f), Translation, SlidingSpeed);

There is no reason to multiply the gravity by 1000, the constructor doesn't divide this value.
I have made a little test case, the gravity of the animator is augmented at each call of this function :
https://dl.dropboxusercontent.com/u/244 ... _clone.zip

patch :

Code: Select all

Index: source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp
===================================================================
--- source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp (revision 4915)
+++ source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp (working copy)
@@ -270,7 +270,7 @@
 
    CSceneNodeAnimatorCollisionResponse * newAnimator =
        new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius,
-               (Gravity * 1000.0f), Translation, SlidingSpeed);
+               Gravity, Translation, SlidingSpeed);
    newAnimator->cloneMembers(this);
    return newAnimator;
 }
 

Re: Jump CollisionAnimator

Posted: Sat Nov 29, 2014 7:42 pm
by kinkreet
JLouisB wrote:Up, this bug is still in Irrlicht (also reported here)

My little patch to fix this problem :

Code: Select all

Index: CSceneNodeAnimatorCollisionResponse.cpp
===================================================================
--- CSceneNodeAnimatorCollisionResponse.cpp (revision 4908)
+++ CSceneNodeAnimatorCollisionResponse.cpp (working copy)
@@ -189,7 +189,8 @@
            = SceneManager->getSceneCollisionManager()->getCollisionResultPosition(
                World, LastPosition-Translation,
                Radius, vel, CollisionTriangle, CollisionPoint, f,
-               CollisionNode, SlidingSpeed, FallingVelocity);
+               CollisionNode, SlidingSpeed, FallingVelocity * (f32)diff * 0.20f);
+        // FallingVelocity is multiplied by 0.020f instead of 0.001f simply because with this value, gravity and jump value don't have to be changed in the Irrlicht examples + demo (Otherwise the solution is to change jump/gravity value in demo, examples 7 and 21).
 
        CollisionOccurred = (CollisionTriangle != RefTriangle);
 
Package with patch, test case application and comments :
https://dl.dropboxusercontent.com/u/244 ... endant.zip

Can you fix this bug for a next release please ?
Thanks
In relation with this bug, when the gravity vector turns (0 ,0 ,0), sets the Falling variable as False in CSceneCollisionManager::collideEllipsoidWithWorld() method.

Code: Select all

Index: CSceneCollisionManager.cpp
===================================================================
Method: collideEllipsoidWithWorld()
-   if (gravity != core::vector3df(0,0,0))
+   if (gravityEnabled)
    {
        colData.R3Position = finalPos * colData.eRadius;
        colData.R3Velocity = gravity;
        colData.triangleHits = 0;
 
        eSpaceVelocity = gravity/colData.eRadius;
 
        finalPos = collideWithWorld(0, colData,
            finalPos, eSpaceVelocity);
 
        outFalling = (colData.triangleHits == 0);
    }
 
 
Easy to fix with a boolean to indicate if you are using gravity.

Regards!!!

Re: Jump CollisionAnimator

Posted: Sun Nov 30, 2014 11:18 am
by AReichl
Question:

+ CollisionNode, SlidingSpeed, FallingVelocity * (f32)diff * 0.20f);
+ // FallingVelocity is multiplied by 0.020f instead of 0.001f simply because with this value,

should it be 0.20f OR 0.020f ???

And i am not so sure about this all. In "CSceneNodeAnimatorCollisionResponse::animateNode" you can find the line
FallingVelocity += Gravity * (f32)diff ...
with diff = timeMs - LastTime. So at least this is frame independent.

Another way to test for frame independence is to manipulate the internal timer (e.g. "slow motion"). If everything still works it's probably frame independent.

Re: Jump CollisionAnimator

Posted: Sun Nov 30, 2014 3:00 pm
by JLouisB
should it be 0.20f OR 0.020f ???
It's a mistake, it's 0.2f.
And i am not so sure about this all. In "CSceneNodeAnimatorCollisionResponse::animateNode" you can find the line
FallingVelocity += Gravity * (f32)diff ...
with diff = timeMs - LastTime. So at least this is frame independent.
The velocity is frame independent and well computed, but it's not the movement at each frame.
The velocity is the derivative of the movement, it's a speed, so this value should also be multiplied by the delta time to have the deplacement vector.

Re: Jump CollisionAnimator

Posted: Sat Jun 04, 2016 7:58 pm
by CuteAlien
svn trunk 5305 has fixed most of those now. Still missing the one with "gravityEnabled" (have to check first what this is about).

I didn't multiply with 0.2 ... that kinda gave the same values when you had 50 fps before, but otherwise makes no sense. So acceleration should now be as documented instead.

This means also that pausing timer works now for this animator (didn't work before).

My test is the gravity.cpp code at https://bitbucket.org/mzeilfelder/irr-p ... -micha/src