Raycasts and Update()

I am using raycasts inside Update() for player movement collision detection. This works fine except when I set the game quality to “Fantastic”. In this quality I notice that my character sinks into the walls very slowly while I hold the movement input down.

When I switch to FixedUpdate() instead then it works fine in “Fantastic” but then my inputs don’t always get read.

Should raycasts be used in update() or fixedupdate()?

your input code should be in update …since it will be detected every frame. Whereas if you are using raycast consistently then you should use it in fixedUpdate. If you are casting ray on any input then put raycast in update.

I think the problem was something else. The problem was that the player was “sinking into walls” which I thought was from the raycasts so I put them in FixedUpdate() which eliminated the issue.

I was multiplying the movement by Time.deltaTime but I recently found something better which is Time.smoothDeltaTime, Unity - Scripting API: Time.smoothDeltaTime, lol, not sure why I didn’t see this before. Now the raycasts work perfect in Update() as well and the movement / animation / camera movement is so much smoother now. Everything looks perfect.

So I guess if your doing any kind of movement or animation then be sure to use Time.smoothDeltaTime.