- Home /
Debug.DrawLine problem
Hello,
I added a Debug.DrawLine to a script I found, and it's supposed to show me the raycast in the scene view.
However, it draws a line from the correct first position to a random one, not 10 units forward.
Any help?
#pragma strict
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
Debug.DrawLine (transform.position, Vector3.forward * 10, Color.red);
if (Physics.Raycast (transform.position, fwd, 10))
{
print ("There is something in front of the object!");
}
}
Comment
Best Answer
Answer by whydoidoit · Oct 17, 2013 at 06:52 PM
I think you meant Debug.DrawRay if you want to use a direction and you want to use the fwd you calculated (though that is just transform.forward).
Debug.DrawRay(transform.position, transform.forward * 10, Color.red);
if(Physics.Raycast(transform.position, transform.forward, 10))
...
Your answer
Follow this Question
Related Questions
Can someone explain to me why this raycast doesn't fire straight? 1 Answer
Find a point at a distance from point on a line passing through two points 1 Answer
when my player touch the obstacle then going inside obstacle 0 Answers
Plane.Raycast layerMask? Using both Physics and Plane raycast 0 Answers
Physics.Raycast 2 Answers