- Home /
Raycast hits when missing a collider, misses when hitting a collider?
These screenshots are the best way to explain. Blue rays are misses, and red rays are hits. The raytrace is looking for collision with the sphere colliders, but the points where a hit is returned are...weird and inconsistent, as you can see. Here's the code where the raytraces are happening:
//Shoot raycast on click
if (Input.GetMouseButtonDown (0))
{
RaycastHit hit;
if (Physics.Raycast(lineStart, lineEnd, out hit, 200.0f))
{
//Debug draw a red line on a Person hit, a blue line on a miss
string hitName = hit.collider.gameObject.name;
if (hitName.Contains("Person"))
{
Debug.DrawLine (lineStart, lineEnd, Color.red, 120.0f);
Debug.Log(hitName);
} else
{
Debug.DrawLine (lineStart, lineEnd, Color.blue, 120.0f);
}
}
}
edit: I've found that if I reset the position of the source object (the object that the raycasts originate from), it works correctly. I also noticed that the LineRenderer component is causing the source object's transform to behave strangely. When LineRenderer is enabled, a small white plane appears at 0, 0, 0. That plane doesn't move, but if I move the source object, it's transform will always be halfway between the object mesh and the LineRenderer white plane thingy. I suppose this may have something to do with the problem?
Your answer
Follow this Question
Related Questions
Returning list of Triangles, Vertices or Points by raycasting through a mesh (iPhone) 1 Answer
Physics.Raycast not checking layermask properly? 1 Answer
How to prevent a sphere from jumping? 0 Answers
Can't raycast on Character Controller? 1 Answer
Trouble with RayCast, rigid body and the colliders tag 0 Answers