- Home /
What should I do to debug this raycast?
Physics.Raycast (mytrans.position, direction, hit, range,layerMask)
I want to do the usual raycast linedrawing but it doesn't function as I want it to.
Answer by Statement · Jan 09, 2011 at 03:24 PM
Use Debug.DrawRay.
var hit = Physics.Raycast (mytrans.position, direction, hit, range, layerMask);
Color color = hit ? Color.green : Color.red;
Debug.DrawRay(mytrans.position, direction, color);
This will cause the ray to become green when it is a hit and red when it is a miss.
I previously suggested Gizmos.DrawRay but it is much harder than Debug.DrawRay.
Thanks man, seems the problem is with the actual ray.. since it casts itself from the transform it collides with the ground collider (afaik), causing unwanted actions :< I'll see if I can figure it out!
You could create a utility gameobject that just is a position where to begin your raytrace. Its flexible and easy to adjust.
That did it! I can't believe I didn't try it earlier, thanks a bunch!
Your answer
Follow this Question
Related Questions
Raycast feelers not reading in all four directions. 0 Answers
Debug.DrawRay not drawing since upgrading my project to 3.3.* 1 Answer
Draw raycast in final build 2 Answers
Raycast not drawing 1 Answer
Determine length of Debug.DrawRay ray 3 Answers