- Home /
How to debug the direction of a rotation
Hello all,
I am wondering how I can use Debug.DrawRay (or Debug.DrawLine?) to show me the direction of the rotated object.
I am wanting to start from the position of the player (transform.position?) and then point in the direction of the rotation forward.
Answer by aldonaletto · Jul 13, 2017 at 12:26 AM
Just add this line to the Update function of your object:
Debug.DrawRay (transform.position, transform.right, Color.red, 0f, true);
But remember to click the Editor's button Gizmos (the button, not the drop-down icon), or the ray won't be visible in the Game window. You may also want to select another transform direction (transform.forward or transform.up), case transform.right is the rotation axis.
EDITED: If you want to show the forward direction based on a Quaternion (say, theQuaternion), do the following:
Vector3 fwd = theQuaternion * Vector3.forward;
Debug.DrawRay (transform.position, fwd, Color.red, 0f, true);
if you want to show right and left then change it to this:
if (turningLeft) Debug.DrawRay (transform.position, -transform.right, Color.red, 0f, true); elseif (turningRight) Debug.DrawRay (transform.position, transform.right, Color.red, 0f, true); else Debug.Log ("NotTurning")
Awesome that gets the line but I don't want transform.forward, I want the "forward" direction depending on rotation angles. For example, when rotation on the Y axis it should show forward from that, not the transform but a public Quaternion.
To be more detailed, my movement is based on UNET, so when UNET sends back what it thinks the player's rotation is I want to draw a line forward from that, which is the Quaternion.
Not sure if that's what you're looking for, but I've edited my answer and included a way to show the forward direction based on a given Quaternion.
Your answer
![](https://koobas.hobune.stream/wayback/20220612130130im_/https://answers.unity.com/themes/thub/images/avi.jpg)