- Home /
Lag at first second of transform.Translate movement
I am trying to move an object in 2D world at a constant speed, but at first seconds when the movements starts it has a lag. I am using transform.Translate
function to move my object, does anyone have an idea on what exactly is going on?
I have not added rigidbody to the object, so gravity would not be the one what causes the lag. I really doubt that it is my monitor becuase I have seen youtube videos where people achive the same result in 3D.
transform.Translate(Vector3.up * Time.deltaTime * speed);
Answer by Harinezumi · Jun 18, 2018 at 11:50 AM
The code is correct for moving an object vertically independent of FPS at a speed specified by speed
variable.
What do you mean by "lag"? Is it that in the first second the movement seems jerky, not fluid? The cause of that is that at the start of a scene Unity is still initializing many things, so the frame rate will be usually lower, which can cause jerky movement. There is no real solution to this, except to add a wait to the beginning of a scene, like a pause, or a countdown until the action starts.
Yeah you pretty much explained the idea yourself perfectly, I will then add a wait to the beginning. Thanks for help.
@Alberts Set this comment to an answer. Please accept it as you've chosen Harinezumi's response as the answer to close this question.
Answer by Bunny83 · Jun 18, 2018 at 12:23 PM
I have not added rigidbody
Well, that's the problem if the object has any sort of collider. Objects with colliders without a rigidbody should never be moved. Any sort of moving object that has a collider must have a rigidbody component attached. If you don't want the object to be affected by collisions or gravity just make the rigidbody kinematic. That way it can only be moved from script. Though it still correctly interacts with other non-kinematic rigidbodies.
Your answer
![](https://koobas.hobune.stream/wayback/20220612164958im_/https://answers.unity.com/themes/thub/images/avi.jpg)