How to convert EulerAngles to Forward Direction?

I want something like this

    private void Start()
    {
        // The euler angle
        Vector3 angle = new Vector3(0, 90, 0);
        // The forward direction with that rotation
        Vector3 direction = Singularite(angle);
        // This is just used to print the result
        Debug.Log(direction.ToString());
    }
    public Vector3 Singularite(Vector3 eulerAngles)
    {
        // Do the math here, I can't find the correct one and that's what I'm searching
    }

The result must be
(1, 0, 0)

EulerAngles in this means rotation in Vector3, Forward Direction here means I want a singular direction in Vector3

I can just make a new gameobject and assign the eulerAngles to the transform and then getting the tranform.forward of it. But it’s not optimized. (I tried to go to definition for transform.forward but it leads to no code to be found.)

and so on, I need to do it with various of eulerAngle, that’s why I tried to make a function for it.
and I don’t know the exact method on how to do that. Can someone help me?

Steps to success:

  • Make a Quaternion using Quaternion.Euler() factory

  • Rotate whatever you consider your starting vector by that Quaternion.

var rot = Quaternion.Euler( 0, 90, 0);

var forward = Vector3.forward;  // fairly common

var result = rot * forward;
4 Likes

I tried it but the result is (0.9999999, 0, 5.960464e-08)?

but it still worked so you got the like

That would be floating point precision. You can round to get what you need.

Okay, thank you for your answer!