What is the idea of multiplying by DeltaTimeSeconds?

Hi brothers,

Look at this code:

// DegreePerSecond = 5
auto ElevationChange = DegreePerSecond * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;

auto ElevationRaw = RelativeRotation.Pitch + ElevationChange;

new code:

// DegreePerSecond = 5
auto ElevationChange = DegreePerSecond;

auto ElevationRaw = RelativeRotation.Pitch + ElevationChange;

What is the idea or main advantages for elevating the barrel with multiplying by DeltaTimeSeconds although i can do that without using it ?!

Maybe this will help you:

Client A is able to sustain a frame rate of 100fps
DeltaTime will approximate 0.01
Each tick his actor will move 100 * TimeDelta units forward.

Client B has a slower machine and is barely getting 25fps
DeltaTime approximates 0.04
Her actor also moves 100 * TimeDelta units forward each frame.

The net result is that both actors appear to move the same distance and have the same speed, independent of frame rate.

It’s common practice to pass DeltaTime on as a parameter to functions that are called from Ticks, assuming it’s relevant to their purpose.

function MoveMyActor( float deltaTime )
{
    Location += Velocity * deltaTime;
}

Hi Mohammed,

as QueueButton already mentioned: for Frame Rate Independence.

And in addition: your variable is DegreePerSecond: means 5 degrees per second as a speed value for the elevation.

But the code is run on every Frame. So at a 100 FPS this means the movement for this frame should be only done for a 10ms period. So you multiply by the frame delta time (0.01) and get 0.05 degrees for ElevationRaw to move for this frame. After 100 frames (= 1 second), this adds up to 5 degrees, which is the speed you defined in your variable.

In your new code example, you instead add up the whole 5 degrees at each frame, making 500 degrees rotation within one second, which will make the barrel just jump up/down instead of smoothly move.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms