What's the difference between engine.getDeltaTime and scene.getAnimationRatio?

Hi,

I’m trying to understand the difference between engine.getDeltaTime and scene.getAnimationRatio. Can someone help me to understand it?

Another thing that I noticed is: when using FollowCamera to follow an object that is moved using elapsedTime = engine.getDeltaTime, the camera goes tremulous. If I remove the elapsed time, the camera movement is smooth. Am I making something wrong?

I’m using this code to move my object:

let elapsedTime = (GAME.engine.getDeltaTime() / 1000),
     gravity = (this.godMode) ? 0 : (this.gravity / 100);

this.mesh.moveWithCollisions(new BABYLON.Vector3(
            0, 
            gravity, 
            this.speed * elapsedTime
));

Thanks by help!

Hello!
So Delta time is the time in ms between two frames.

getAnimationRatio will return a ratio (a factor ) so let’s say you are running at 60fps then the ratio will be 1. If you run a 30fps then the ratio will be 2

So the idea is to use the ratio and multiply it by your step

2 Likes

Thanks @Deltakosh I’ll try changing from delta time to animation ratio.

Regards,
Tiago

I’m resurrecting this old post from 7 years ago because yesterday I was thinking about this. I decided to do some research and discovered that I had already asked this question so long ago, haha ​​. So, I decided to add some information in case someone has the same doubt as I, and also for me in another 7 years.

But I always use deltaTime, and yesterday, I found myself wondering: What is the purpose of animationRatio?

So, after thinking about it for a while, I came to the following conclusion:

The animationRatio is very useful if I want to perform consistent movements based on a specific time. For example, if I want to move a cube 10 units in one second:

1 - I know that the animationRatio works at a base rate of 60FPS. When the FPS is 60, it returns 1. If it is 30, it returns 2. If it is 120, it returns 0.5
2 - If my application always ran at a fixed 60 FPS, I would only have to move my cube like this (I am dividing by 60 so that it takes 1 second to move the cube):

cube.position.x += 10 / 60 //10 units / 60 fps

3 - But the issue is that FPS is not fixed, so if I multiply everything with the animationRatio, I am ensuring that the movement will occur as if the rate were 60 fps (since, if my fps is double, 120, animation ratio will be half, 0.5, balancing the movement):

cube.position.x += (10 / 60) * animationRatio

So, from what I understand (please correct me if I’m wrong), animationRatio is very useful for cases where I want to move the object exactly X frames.

And knowing that multiplying by animationRatio, we are considering 60 frames per second, I can control exactly how long my animation will last. In other words, if I want something to last 5 seconds, I divide the steps by 5.

I never realized this because I usually use the Animation class to do this, but I now have a clear idea of ​​its use.

In the case of deltaTime, we are talking about something similar, but I am not concerned with how many frames it takes for something to happen. I just want my object to travel the same distance regardless of the FPS (which, in the end, is practically the same thing, but seen from a different angle, haha).

In other words, if I want a rocket to have X speed regardless of the FPS, I use deltaTime. Suppose I want a rocket to take exactly X seconds to get from one point to another. In that case, I could use deltaTime for that (and simply calculate the animationRatio manually), but the animationRatio is already there, ready to use in such cases.

I hope this is useful, and I would be grateful if someone could correct it or add more information.

Thanks!

3 Likes