- Home /
¿Why Raycast sometimes don't collide with rigidbody (plus collider)?
I have a Gameobject with collider and rigidbody, the Gameobject is not moving nor rotating. I perform a single raycast through it and sometimes returns false, sometimes collide and returns true as expected.
Now the weird thing, if I put a static collider behind that Gameobject, the raycast return true and the collision point is in the collider of the Gameobject with rigidbody not in the "background" static collider.
Without that static collider, if I keep raycasting, eventually returns true, also weird...
In the images the debuglines are, cyan = raycast = true, gray = raycast = false.
Note: If I remove rigidbody of sphere raycast always returns true.
That behaviour makes raycast unreliable. I workaround placing six huge and distant quads without renderer and build my scene inside that "cube", but that is not the correct way to go i suspect...
As side note, SphereCast with a .0001f radius, works as spected, returns true without static collider as background. But I believe that is more expensive than raycast.
Your answer
Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Multiple hit detection with Raycasting? 2 Answers
Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers
Physics.Raycast doesn't hit anything even though Debug.DrawRay works 1 Answer
how detect "OnRaycastOut" 1 Answer