- Home /
Raycast/Non-Physics Collider Discrepancy
Hey fellas, got a quick problem--
I have a script that moves an object around using a simple transform.position += velocity system (no physics involved). The main camera is attached to this object, and the camera rotates using the mouse. Every Update() I fire a ray from the center viewport of the camera and read which colliders the raycast collides with.
I have a few different objects with colliders attached to the object, and I'm surprised to find that the raycast sent from the camera does not always hit the colliders. Once the object is moving fast enough, the raycasts fail. It seems as though the raycasts are "falling behind" the colliders, but I have been unable to solve the issue by reordering the scripts or using any combination of Update()/FixedUpdate()/etc.
Is there a general "best practice" for when to use a Physics.Raycast() against a moving object that is not controlled via native physics?
Thanks!
It stands to reason that I've been running all of my transform.position updates in Update(), and then I attempt the Physics.Raycast() calls in LateUpdate(). I'm boggled at how they are still failing.