Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation.
I am drawing a ray like this:
Debug.DrawRay(transform.position, new Vector3(1,1,1), Color.green, 1.0f / 60.0f);
But when i rotate the game object in x, y or z the direction of the ray is constant. I want to modify the direction so that it is relative to the game objects rotation:
I have looked at the quaternion functions and found that using something like this Quaternion.FromToRotation(transform.forward, transform.right) * new Vector3(1, 1, 1)
might do the trick. But i don't understand what exact arguments i should give the function to make the direction rotate correctly in every axis.
Answer by unity_p1ZEBD9IvIhlOQ · Aug 28, 2018 at 01:01 PM
Okay, i just tried`transform.rotation * new Vector3(1, 1, 1)` and it worked. I do not really know why it worked though. Could any one explain it?
Your answer
Follow this Question
Related Questions
How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer
Something seriously weird is going on with my transform.eulerAngles 0 Answers
copy rotation script doesent copy the full 360 degrees? 0 Answers
Using a directional vector to orient a sphere? 0 Answers
Quaternion.Euler doesn't work right? 2 Answers