# Get Y axis of Vector?

I’m trying to get the Y axis of a direction vector so I can rotate a point 90 degrees to the left and right. I thought I had the logic right, but something isn’t quite right because the points that I create are not a straight line. Can anyone give me any advice?

Even if the axis was wrong, i would still expect the points to be a straight line because I’m rotating -90 to 90 around some distinct axis.

Given that “direction” is the direction from point “current” to point “next”.

``````                    Quaternion q = Quaternion.LookRotation(direction);
q.ToAngleAxis(out angle, out axis);

Vector3 left = Quaternion.AngleAxis(-90, axis) * direction;
Ray leftRay = new Ray(current, left);
left = leftRay.GetPoint(2);

Vector3 right = Quaternion.AngleAxis(90, axis) * direction;
Ray rightRay = new Ray(current, right);
right = rightRay.GetPoint(2);
``````

Picture of the result. As you can see, there is no way that the three points can possibly line up.

So, I ended up doing something like the following. Can anyone give me a better way? I hate creating a game object just to get the up vector of my object. I’m sure there must be some math way to do it.

``````        Transform t = new GameObject().transform;

direction = next - current;

t.position = current;
t.rotation = Quaternion.identity;
t.LookAt(next);

Vector3 left = Vector3.Cross(direction, t.up);
``````

transform.right, transform.forward and transform.up will get you the X,Y,Z facing of an object and you can perform calculations on these without having to create a new game object if the script itself is attached to the object you are trying to get axis for.

1 Like