If the game is running at 10 frames per second (you can never be sure what frame rate you game will be running at on all systems!) then the ball will move 10 pixels in 1 second, meaning it’s moving 10 times slower! If the frame rate of the game is 100 then the ball will have moved 100 pixels in 1 second. Lets say you have a ball moving across the screen at 1 pixel per frame.
how does the deltaTime help me with slower movement? You will want to use deltaTime movement in combination with either lerping or a interpolated rigidbody! (Both explained in their sections below!) But wait. Note: Using only deltaTime alone may still give stutter at lower framerates or at higher movement speeds. Unity has a variable named deltaTime (ltaTime) which gives the time in seconds since the last Update() call as well as fixedDeltaTime (Time.fixedDeltaTime) which is the constant time since the last FixedUpdate() (Which is a consistant value changed in the time manager or directly changed via script, but it’s handy to have) (Tip: Using ltaTime inside a FixedUpdate() will give you the fixedDeltaTime value) Otherwise when the frame rate of the game changes, the speed of the objects will also change! Moving objects based on frame rate is very important for creating smooth movement. position of a moving object per frame will create a lot of stuttering.Īdapting movement to the framerate with deltatime Setting the position of an object which already has a rigidbody with gravityĭirectly setting the.
Try adding some debug logging to make sure the movement code isn’t being called multiple times – if not disable it and make sure no others scripts are moving the object!
Interpolation not set when using a rigidbody.
Lerping will smoothly blend from position a to position b, read the lerping section below for more info! Position not being lerped or interpolated.Script not taking frame rate into consideration when moving an object without a rigidbody.Īn object being moved 1 pixel per frame would jump and change speed as the frame rate changes!.
This guide explains the different options for smooth movement and explains what lerping and deltatime are as well as how to use them! (Very important and useful to learn when developing Unity games) Possible causes for movement jitter Not using a rigidbody: There are many causes for objects to stutter when being moved in Unity.