Framerate-independent movement and DeltaTime – ShiVa Engine

Framerate-independent movement and DeltaTime

Physics-based movement:
The physics engine (as well as the animation engine) are already FPS independent, so no needs to use the frame timing. That means for your movement code, all dynamics.* commands are already fps independent.
Standard Movement and Rotation:
movement and rotation realized with object.setTranslation and object.setRotation and alike will be framerate dependent and thus need normalization by a framerate-dependent factor.
the ‘dt’ delta time:
shiva uses a factor called dt (delta time) that helps you to get your movement and rotation framerate-independent.

local dt = application.getLastFrameTime()

it is also advisable to limit your framerate to a reasonable value. this is done by:

application.setMinFrameTime ( nValue )

set nValue to a number you want, it is calculated by 1/(Max FPS you want to allow).

--get the same rotation on all fps rates as if it was 60 fps
local nIncrement = math.interpolate ( this.nRotationAmount ( ) / 100, 360, application.getLastFrameTime ( ) * 60 )
this.nRotationAmount ( this.nRotationAmount ( ) + nIncrement )

a framerate independent movement could look like this:

--move at a constant speed
local dt = application.getLastFrameTime()
object.translateTo (this.getObject(), 0,0,1, object.kLocalSpace, dt * 60 )

Need more answers?

  • slackBanner