Physics.Raycast hit question
Hi all, I have the following script attached to my main camera:
void Update () {
Vector3 startPosition = transform.position;
Vector3 direction = transform.forward;
Debug.DrawRay (startPosition, direction * 100f, Color.red, 0.2f);
Ray ray = new Ray (startPosition, direction);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
Debug.Log ("hit object: " + hit.collider.gameObject.name);
}
}
And I have three objects in the Scene with colliders. What happens now is- when I rotate the camera - that "sometimes" when the red line hits one of my objects I get the debug message - but sometimes not. How come that the ray "sometimes" seem to hit objects and sometimes not ?
Thanks in advance
Comment
Your answer
Follow this Question
Related Questions
how do I call a function from another script, when Raycast Hits? 1 Answer
Check if position is inside a collider 5 Answers
Raycast hit 2 Answers
Highlighting with a Raycast 1 Answer
get array of RaycastAll hits 1 Answer