# Draw line for debugging

Hi, I’m trying to draw a line for debbuging and I’m having a problem for getting the coordinates.

I’m using this script from stealth project in assets store, but how can I draw two lines that represent the angle of this code.

``````void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
direction = other.transform.position - transform.position;
angle = Vector3.Angle (direction, transform.forward);

if (angle < fieldOfViewAngle * 0.5f)
{
Debug.Log("Insight");
//Destroy(other.gameObject);
}
}
}
``````

the fieldOfViewAngle is = 110 degree, how can I draw two lines, the first is in 0 degree, and the other is in 110 degree in forward position and relative to my character transformation. thanks

I haven’t tested this but what I’d probably do is something like this:

Create a vector3 with the direction you’re looking for. For instance, if it was 110 degrees then:

float AngleX = Mathf.Sin( 110.0f * Mathf.Deg2Rad );
float AngleZ = Mathf.Cos( 110.0f * Mathf.Deg2Rad );
Vector3 AngleVec = new Vector3( AngleX , 0.0f , AngleZ );

Now you want to give it a length - e.g. 10 metres

AngleVec *= 10.0f;

Then you can rotate this vector by your characters transform matrix so it’s always pointing in the correct direction relative to the character. e.g.

Vector3 LineEndPos = transform.TransformVector( AngleVec );

thanks, it was working, but when my character start moving around the planes, it become wierd, it only works when the transform position of my character is at (0, 0, 0). how can i make it to work even if my character is moving? thanks

bump? anyone?

Think it should have been TransformPoint rather than TransformVector - the vector one doesn’t add the position of the character onto the end result. Unity - Scripting API: Transform.TransformPoint

cheers, it works! thanks alot

you can also do “debug” stuff with OnDrawGizmos(…), it add the lines to the scene view instead of in game if that’s at all useful…