0
\$\begingroup\$

I want to draw ray to check how my raycast works in Unity editor.

However all above code doesn't seems to work, drawn ray is always super long.

float m_Distance = 1f;

// Try 1
Vector3 forward = transform.TransformDirection(Vector3.forward) * m_Distance;
Debug.DrawRay(transform.position, forward, Color.green);

// Try 2
Debug.DrawRay(transform.position, transform.forward.normalized * m_Distance);

Is there an anything wrong with my approach? Using Unity 2018.3.12f1.

\$\endgroup\$
  • \$\begingroup\$ I don't see anything wrong with this particular piece of code. \$\endgroup\$ – Ocelot Jul 15 at 14:40
  • \$\begingroup\$ @Ocelot That's why I'm stuck in here. \$\endgroup\$ – modernator Jul 15 at 14:43
  • \$\begingroup\$ How is it "super long", though? There might be some pattern to it that could lead us to the cause. \$\endgroup\$ – Ocelot Jul 15 at 14:57
  • \$\begingroup\$ I'm unable to reproduce this problem. In my tests, the length of the second argument vector is faithfully reproduced in world units in the scene view. Can you create a minimal complete verifiable example that lets us reproduce this problem in a new empty Unity project? \$\endgroup\$ – DMGregory Jul 15 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.