Author Topic: Rotate Vehicle to Face Player Eye Vector [Solved]  (Read 2011 times)

I want to setTransform a vehicle to face diagonally upward if my Blockhead is facing diagonally upward. Using the Blockhead's transform doesn't work because it does not include looking up or down.
« Last Edit: October 25, 2013, 10:52:16 PM by tommybricksetti »

Get the players eye vector, convert that into a transform using some trig.

Get the players eye vector, convert that into a transform using some trig.
Do you know how to actually do that? %obj.getEyeVector(); is the code for getting the eye vector.

This is untested, ripped apart some other codes.
Code: [Select]
function getEulerFromVector(%vec)
{
%pi = 3.1415926535897932384626433; //Or use $pi
%x = mASin(getWord(%vec,0)) * 180 / %pi;
%yaw = 180 - mFloatLength(%x / mAbs(%x),0) * (180 - (mACos(getWord(%vec,1)) * 180 / %pi));
%pitch = mASin(getWord(%vec,2)) * 180 / %pi;

return %yaw SPC %pitch SPC 0;
}

Then, use %obj.setTransform(%obj.getPosition() SPC eulerToAxis(getEulerFromVector(%player.getEyeVector())));


Actually, i'm gonna add that function to my function list..
« Last Edit: October 20, 2013, 03:19:55 PM by boodals 2 »

Decently sure you could also just use MatrixCreateFromEuler(vectorScale(%player.getEyeVector(), 1.5707)) to get the axis angle.
« Last Edit: October 20, 2013, 06:03:44 PM by $trinick »

I've never understood any of the matrix functions, care to explain them?

Well, the MatrixCreateFromEuler function takes X Y Z radian angles and turns it into an axis angle at position 0 0 0. Scaling your eye vector by 1.5707 should be sufficient to get radian X Y Z values for rotation. Then, you just pop that Euler X Y Z angle into MatrixCreateFromEuler to get something like "0 0 0 0 0 -1 3.14159", then you can chop off the first 3 words and stick in the position you want it at.

EDIT: Realized you should scale by 1.5707 not 3.14159.
« Last Edit: October 20, 2013, 06:03:33 PM by $trinick »

Code: [Select]
%pi = 3.1415926535897932384626433;

Pretty sure that's the equivalent of using a high-precision laser to lobotomize a roosterroach, as opposed to just finding a heavy object to flatten it with.

Pretty sure that's the equivalent of using a high-precision laser to lobotomize a roosterroach, as opposed to just finding a heavy object to flatten it with.
that was a good metaphor

Pretty sure that's the equivalent of using a high-precision laser to lobotomize a roosterroach, as opposed to just finding a heavy object to flatten it with.
Giggled

Figured it out.
Code: [Select]
%pos = %obj.getPosition();
%tra = %obj.getEyeTransform();
%rot = getWords(%tra,3,6);
%vehicle.setTransform(%pos SPC %rot);

Does eyetransform rotations really give accurate xy rotations?


sure does.

P sure MM is talking about the situations in which the eye vector is rotated with respect to the body of the player, IE freelooking. In these cases the eye vector does not represent an accurate rotation, and instead is... need I say it... the vector of the eye.

P sure MM is talking about the situations in which the eye vector is rotated with respect to the body of the player, IE freelooking. In these cases the eye vector does not represent an accurate rotation, and instead is... need I say it... the vector of the eye.
Test it and tell us the results.