- Home /
Moving an object in Start() vs moving an object in Update() with Time.deltaTime
What is the advantage of moving an object on one frame versus moving an object on multiple frames with Time.deltaTime?
// Moving an object only once
// Assuming that the object doesn't have any drag or friction.
void Start()
{
rb.velocity = Vector2.right * speed;
}
// Moving an object through multiple frames
void Update()
{
rb.velocity = Vector2.right * speed * Time.deltaTime;
}
Could you explain why this question is wrong? Maybe I did not explain it correctly?
Answer by Long2904 · Jul 04, 2021 at 11:25 AM
So @Llama_w_2Ls was right. Changing velocity will not make the position change instantly. The rigidbody.velocity will always change per second. This post explains it in more detail.
Answer by Llama_w_2Ls · Jun 27, 2021 at 12:49 PM
There's no need to multiply rb.velocity by Time.deltaTime. Whether the velocity is set 500 times per second or once, the speed will still be consistent across all frame rates.
If your object has no drag or friction and therefore its velocity will never be reduced, setting the velocity in start is more optimal. There's no difference really.
However, if this is the case, you really don't even need a rigidbody in the first place. Just update the transform position every update instead (with regards to Time.deltaTime).
I changed the velocity in the Update method, if I didn't multiply with Time.deltaTime then players who have a faster frame rate will move faster, players who don't will move slower. Multiplying with Time.deltaTime will make the velocity distance per second rather than distance per frame.