Should i multiply acceleration and speed by Time.deltaTime in my custom movement or just one of them?

Should I multiply acceleration and speed by Time.deltaTime in my custom movement or just one of them?

For example:

speed += aceleration * Time.deltatime;
transform.position += speed * Time.deltatime;

or

transform.position += speed;

What should i do for it to remain consistent in different pcs?
Would it matter if it was in FixedUpdate() as opposed to Update()?

The code in my game is obviously more complex and i’m directly modifying a Rigidbody’s velocity in FixedUpdate() but basically this is my doubt.

Yes, you need to multiply both with Time.deltaTime since the velocity is the time integral of the acceleration and the position is the time integral of the velocity. However the way you process acceleration, velocity and position gives you a frame dependency because deltaTime is a linear factor which can only correct linear relationships. Since position and acceleration have a quadratic relationship, the higher the framerate, the bigger the error.

This question has been asked several times in the past. Have a look at my answer over here for an example

Over here i’ve posted a table with example values which show the difference

One time is enough otherwise it will lower the value too much. Because deltatime = 1/fps.
So let say you have 2pcs.

  • PC 1 gives you 60 frames per seconds (fps)
  • PC 2 gives you 30 fps
  • Let say you movement speed is set to 10f.
  • So if you don’t use Time.DeltaTime then in PC 1 the object will move 10*60 = 600 units per second
  • And speed in PC 2 will be 30*10f = 300units per second.
  • So the first thing they will move very fast and the speed will vary from PC to PC depending on the PC fps.
  • When you use Time.deltaTime it multiplies the speed by 1/fps so this way speed of both pc will be
  • PC 1: 6010f1/60 = 10units per second
  • PC 2: 3010f1/30 = 10units per second

To find the difference in FixUpdate and Update do this and watch the difference.

void FixedUpdate()
{
      Debug.Log( "FixedUpdate realTime: "+Time.realtimeSinceStartup);
}
void Update()
{
     Debug.Log( "Update realTime: "+Time.realtimeSinceStartup );
}

if you are modifying velocitys in the fixedupdate you dont need to use time.deltatime any time for remaining the same in all pcs. first, to say, if you are working with a rigidbody use the fixedupdate, but if you were moving objects in the update, you would need to do it only once. do you understand the difference between update and fixedupdate and when to use both? since if thats your question probably this answer wont help you to understand the core of your question and i can provide a better explanation.