Author Topic: How do I find the rotation from a vector  (Read 3996 times)

How do I get a rotation getWords(%transform,3,6); from a vector?
« Last Edit: July 24, 2014, 12:31:38 PM by tommybricksetti »

%client.player.getVelocity()

How do I find the rotation from a vector?

Do you mean converting a unit vector into euler angles? theres a sticky on the top of this board about it.

I mean, for example, if I get the left vector, how do I find the axis rotation, so I can rotate the player to the left?

Got it.
Code: [Select]
function faceVector(%obj)
{
%vel = %obj.getVelocity();
%pos = %obj.getPosition();
%tra = %obj.getTransform();
%yaw = mATan(getWord(%vel,1),getWord(%vel,0));
%fix = "0 0 -1" SPC %yaw;
%eul = axisToEuler(%fix);
%eulA = vectorAdd(%eul,"0 0 -90");
%axis = eulerToAxis(%eulA);

%obj.setTransform(%pos SPC %axis);
}

By looking at your code, it appears as if you make the player face along a certain axis relative to his current position, correct?

By looking at your code, it appears as if you make the player face along a certain axis relative to his current position, correct?
yes


My code only finds the z rotation, how do I find the xy?

My code only finds the z rotation, how do I find the xy?
Duplicate and adjust some of the current code you have, you already figured out how to find z. X and y should be the same, with slightly altered values.

I'm pretty sure getTransform will only ever give you a Z rotation because players are locked on both other axes.

If you want pitch/yaw, use getEyeTransform.

I'm pretty sure getTransform will only ever give you a Z rotation because players are locked on both other axes.

If you want pitch/yaw, use getEyeTransform.
Wait, getTransform gives you rotation and not location?

Wait, getTransform gives you rotation and not location?
It gives both.