- Home /
Can I animate objects/cameras in Update() without breaking Physics.Raycast?
Since the beginning of our project, we have been moving and animating both objects and camera always in Update() and/or LateUpdate() (always scaled by Time.deltaTime to compensate for framerate).
However, Physics.Raycast() no longer returns correct and reliable results when doing so - no matter where I do the Physics.Raycast() (FixedUpdate/Update/LateUpdate), it sometimes passes through objects that just moved into the path, and sometimes it works.
Now I noticed that it does work reliably when I do all my scripted animations in FixedUpdate() instead of Update() - again, independently from where I call Physics.Raycast.
So my main question would be: Is this how it needs to be done? Are you forced to do all object transformations in FixedUpdate, if you want to use Physics.Raycast? Or am I missing something, or is there a workaround?
Sometimes some of our objects (or the camera) are also animated using animations created with the Unity AnimationEditor. But when I script-animate the camera in FixedUpdate(), an object with a Unity animation will look extremely jerky. Is Animation.animatePhysics the proper way to fix this? Or is there some other way to influence the read-only value AnimationClip.frameRate (which appears to be 60 for Unity-animatinos, independent of Time.fixedDeltaTime)?
Answer by Panopolos · Jun 24, 2013 at 01:54 AM
I don't know where you're calling for the Raycast, but when I ran into this problem (checking "Animate Physics" broke my Raycast), I changed the call of the Raycast from Update to LateUpdate. I had no problems after that.
Answer by davidjohn123 · Jun 07, 2016 at 11:01 AM
please answer me http://answers.unity3d.com/questions/1198965/detecting-raycast-on-moving-object.html#comment-1199022