Rotating a Unit Vector 3 by 90 degrees?

This is the basic code i am using (well written out easier to read)

Vector3 unitVector = new Vector3 (-1.0f,0.0f,0.0f);
Vector3 rotatedVector;

rotatedVector = Quaternion.AngleAxis(90, Vector3.left) * unitVector;

there is something wrong with this, it’s not rotating by 90 degrees or something.
Is there a better way to rotate the unit vector so it’s at 90 degrees to the first vector?

Thanks for any help!

*EDIT: Vector3.left not Vector3.up

When you Debug.Log(rotatedVector), what is the result? It seems to me that that should work correctly. (I would expect the result to be (0,0,1), give or take a little floating point inaccuracy.)

Sorry, I wrote this free hand without refering to my code, it’s actually Vector3.left
The quaternion returned is {(0.7071, 0.0, 0.0, 0.7071)} and the rotatedVector comes out as -1,0,0 same as the unitVector

This is my actual code, total direction is the direction where it is pointing
and the resulting angle varies between 75 - 90 degrees

Vector3 Rotated = Quaternion.AngleAxis(90, Vector3.left) * totalDirection;

float angle = Vector3.Angle(Rotated, totalDirection);

And as i said if the totalDirection = (-1,0,0) it doesn’t work at all…

So… you’re rotating a vector that’s pointing left, around an axis that’s pointing left? Of course that’s going to be the same result. It’s like having a stick pointing upwards at the North Pole - it’s always gonna face the same direction.

So what would you use to get a rotated unit vector lets say (0.7,-0.5,0.3); what would you use to get a 90 degree angle? my example was a bit messed up as you pointed out.

A 90 degree angle around what? If you’re trying to rotate “to the left” or “to the right”, then the axis you rotate around is going to be Vector3.up.

That’s kind of my issue, the totalDirection is different each time and what it needs to rotate around isn’t one of the predefined values available, if that makes sense.

You have kind of helped already, i think i know how i can fix it, if i randomise position in the x and z i can rotate around the up then… That might have been internal muttering, but basically the total direction is the vector between this object and the origin. and it’s currently created at a random position in the x y and z if i don’t randomise the y i can surely rotate it around the up vector then?

Thank you i have fixed it now, sorry my explaining was obscure! you made me realise what i was doing wrong :slight_smile: