To cut a long story short, I have a very simple code, for now, which makes the rigidbody velocity equals a new vector3 consisting of Input.GetAxes multiplied by speed.
Should I put this code in Update multiplying movement by Time.deltaTime or in FixedUpdate?
Should I handle the GetAxes in Update then cast it to a variable and use it in FixedUpdate ?
If you are doing any calculations with the rigidbody, put it in the FixedUpdate. If you are just assigning values to properties you can really put that where ever…
the problem with putting input code into FixedUpdate is that because fixedupdate isn’t guaranteed to be called every frame your game might miss the input.
This is hugely simplified but it’ll give you the sense of the issues you might face:
Let says you’re sticking with the default 50 frames a second for the physics tick, but you’re game isn’t too taxing and update is running at 100 frames per second.
Now you tap the space bar to “jump” (or whatever) such that the input only lasts for 1 frame. If you have the input code in the fixed update you’ve got a 50/50 chance the input code is caught on the same frame as a physics tick and processed.
What you “should” do is highly dependant on what you are trying to do. If you’re writing a fast paced fighting game, you’ll notice the problems. If you’re writing something a lot slower, you might not.
If you’re setting the velocity based on continuous input (controller stick/keyboard button/mouse held down), you can set it in Update and call it a day. That would be appropriate for something like a shmup.
If you’re reading input events, and applying force a single time, as you’d do if a single key press caused a jump, you’ll want to split it up - do input in Update and apply the input in FixedUpdate.