- Home /
Question by
opri · Jan 08, 2016 at 08:10 AM ·
raycastcollidercollision detection
Raycast passes Collider
When I fire a Ray it will pass a Box Collider assigned to a humanoid model roughly 50% of times (I'm checking it with Debug.Log, please see below). Naturally, I'd prefer getting a hit each and everytime the model is clicked. I'm pretty much running out of ideas.
Code is below. Please see also the image.
private void Update() {
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hit;
hit = Physics.RaycastAll(ray);
for (int i = 0;i<hit.Length;i++)
{
Debug.DrawLine (ray.origin+ray.direction*10.0f, ray.origin, Color.red,10.0f);
Debug.Log("Collider name:"+ hit[i].collider.name);
}
}
}
You can see the ray hitting the Box Collider but on this occasion I didn't get notification. However, when trying again, I might get it or might not. Totally non-deterministic.
screen-shot-2016-01-07-at-234004.png
(128.3 kB)
Comment
Your answer
Follow this Question
Related Questions
Raycast goes through collider 2 Answers
Raycast not hitting collider 2 Answers
How can I determine how many colliders exist along a line? 1 Answer