- Home /
How can I draw a ray for direction object is moving?
Hi, I've been trying to get a ray to draw in the direction a cube is facing but I don't understand how. The reason I'm trying to do this is because I'm making a random moving AI that will rotate in a random direction and move forward.
Here is my code: if( counter <= 0){ counter = 100; dir = Random.Range(0,360); transform.eulerAngles=new Vector3(0,dir,0);
print("change");
}
else
counter --;
Debug.DrawRay(transform.position,new Vector3(transform.position.x,transform.eulerAngles.y,transform.position.z));
Comment
Best Answer
Answer by robertbu · Nov 30, 2013 at 12:05 AM
Debug.DrawRay(transform.position, transform.forward * 5.0f);
The '5.0'determines the length of the ray. Without this value, the ray will be 1.0 in length and therefore stick out of a 1x1x1 cube by only 0.5.
Dam your good. I can't believe I over looked that. Thanks!