- Home /
Raycast and Physics(Ragdolls): Update() or FixedUpdate()?
Hello! This is the situation: I got a Raycast (under Update() function) that when hit an enemy, launch an event that starts a method that enables all its colliders and Rigidbodies (that is, enable the ragdoll). Should I put the Raycast under FixedUpdate()?
Plus, I noticed sometimes the ray doesn't hit the enemy collider. It seems to fire through it. Thanks!
Answer by xxmariofer · Nov 26, 2021 at 02:17 PM
all physics related code, (including raycast) should go in the fixedupdate
Thanks @xxmariofer , but in my case the raycast hit a simple capsule collider (not a ragdoll), and only then, it sends the event. What I say is that the raycast (just indirectly) involve ragdolls code. Should I use two separate raycast? one for the shooting and the other for no-physics interactions? Could be too much expensive in term of performance? Thanks for your help.
Always, doesn't matter what you are using the raycast for, use them in the fixed update. You cannot use raycast for non physics interactions, because raycast are already physics operations itself. I can't tell you what you should be doing without more context, for example, using 1 default raycast is (usually) worse performance than 2 raycast but using layers and Ray leghts. There is a chance, that if having multiple raycast fired let you use more specific rays and they will be better for performance
Your answer
Follow this Question
Related Questions
Ragdoll collision precision 0 Answers
Unity Physics frame rate. void FixedUpdate 3 Answers
Raycast drags behind the transform that generates it 1 Answer
Multiple raycasts in same fixedupdate 3 Answers