I know there are alot of questions about these functions, and the confusion about deltaTimes…but with further research Im only getting even more confused :s
Just wondering if anyone could clarify how they differ?
If I understand correctly, Update is a simple call per frame, and using Time.deltaTime in an update function will give one consistent calling of that function regardless of performance? and FixedUpdate is a constant call primarily for the physics engine, since its constant, using Time.deltaTime in it would be useless…So then what would fixedDeltaTime be used for?
Essentially Im looking to find a way to update an objects position, adding to the x value constantly, to create an illusion of movement, but I want this speed to be constant, regardless of whether the client is using a toaster or a hyperspeed computer. Currently im using
transform.position = new Vector2 (transform.position.x + (Speed * Time.deltaTime), transform.position.y);
in the LateUpdate() function, but since it is something that is dealing with physics, would it be better suited to be called in the FixedUpdate()?
Sorry if some of my assumptions are plain wrong, its just all a bit confusing right now
It actually looks like that code is doing exactly what you described
deltaTime is a measure of the time it took to process the previous frame. By multiplying any “per second” values (speed in your case) by deltaTime, you are inherently ensuring that the speed is applied consistently, regardless of how fast or slow your host device is running the program.
For example, let’s say we have a speed of 10 and two devices, one running at 20fps and another running at 100fps. These devices would have deltaTimes of 0.05s and 0.01s respectively. On each update speed * deltaTime is applied to the position. So that’s a speed of 0.5 and 0.1. Over the course of one second, the first device applies it’s speed of 0.5 twenty times, and the second device applies it’s speed of 0.01 one hundred times. In both cases the position is moved at a consistent speed of 10, independent of the device speed.
It’s also worth mentioning that deltaTime is worth using on any single platform, as it also ensures consistent movement if the frame rate varies while the program is running (as it almost always does).
I hope this quick explanation helps, but a bit of googling on “delta timing” should give you lots more reading material