[mostly fixed]Jump CollisionAnimator

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Squarefox2
Posts: 67
Joined: Mon Feb 02, 2009 10:19 am

[mostly fixed]Jump CollisionAnimator

Post 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
hayate
Posts: 43
Joined: Mon Feb 16, 2009 9:38 pm
Location: Brescia, Italy

Post 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:
Sorry for my awful english ^_^'
Image
Squarefox2
Posts: 67
Joined: Mon Feb 02, 2009 10:19 am

Post by Squarefox2 »

I only call this jump one time, so there are no multiple jumps.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The question is if your movement code is framerate dependent, because the jump() only influences your movement calculations.
hayate
Posts: 43
Joined: Mon Feb 16, 2009 9:38 pm
Location: Brescia, Italy

Post 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 :)
Sorry for my awful english ^_^'
Image
Squarefox2
Posts: 67
Joined: Mon Feb 02, 2009 10:19 am

Post 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.
JLouisB
Posts: 67
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: Jump CollisionAnimator

Post 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
Last edited by JLouisB on Sun Nov 30, 2014 3:02 pm, edited 1 time in total.
JLouisB
Posts: 67
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: Jump CollisionAnimator

Post 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;
 }
 
kinkreet
Posts: 64
Joined: Thu Oct 31, 2013 7:53 pm
Location: Barcelona, Spain

Re: Jump CollisionAnimator

Post 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!!!
AReichl
Posts: 268
Joined: Wed Jul 13, 2011 2:34 pm

Re: Jump CollisionAnimator

Post 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.
JLouisB
Posts: 67
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: Jump CollisionAnimator

Post 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.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Jump CollisionAnimator

Post 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
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply