- Home /
FixedUpdate or Update for movement code?
Hey there!
I've heard that FixedUpdate is the better one for Physics, but even so, I still don't know where to put my movement code:
float XInput = Input.GetAxis("Horizontal");
float ZInput = Input.GetAxis("Vertical");
Vector3 moveVector = transform.forward * ZInput + transform.right * XInput;
cc.SimpleMove(Vector3.ClampMagnitude(moveVector * movementspeed, movementspeed));
Should this code be in Update or FixedUpdate and why? Thank you a lot!
Answer by ryanjvigus · Oct 06, 2020 at 06:22 AM
I'll be honest I'm not super familiar with CharacteController.SimpleMove but I think that it should be in regular Update (). Update () is called at the beginning of every frame while FixedUpdate () is called every physics calculation.
I don't know how it works too well in depth but basically FixedUpdate () is called many times per frame and you're right should be used with most physics related things. However since you're getting the player's input and using that to move something and the players input is only updated every frame, there would be no point in using FixedUpdate () as you would just be moving the object multiple times in the same direction every frame.
I could be wrong about that actually but generally there's not much reason to get player input any more often than every frame.
Your answer
Follow this Question
Related Questions
Physics behaviour changing with framerate - Is FixedUpdate() actually working properly? 3 Answers
Intermittent detection of input in FixedUpdate() 2 Answers
error CS1031: Type expected fix 1 Answer
Fixed timestep... 1 Answer
Different game speed 2 Answers