[Solved; thanks!]Quaternion

Started by Florin Calinescu, Apr 01, 2015, 06:40 AM

Previous topic - Next topic

Florin Calinescu

I have a little question:how to get the quaternion of the player?I tried using something like
local W = player.Pos.W, X = player.Pos.x,Y = player.Pos.y, Z = player.Pos.z;
Message( "Your position:  X:" + X + " Y: " + Y + " Z:" + Z + " W:" + W + "");
but it seems it doesn't work.Can anybody help me please? :'(

.

Unfortunately there is no such function for players. Only the position which returns a 3d Vector with just X, Y, Z components. So, you can't really get the rotation of the player AFAIK.
.

Florin Calinescu

I'll still wait for more answers to get something similar to this

.

Quote from: marmota91 on Apr 01, 2015, 06:47 AMI'll still wait for more answers to get something similar to this


No problem. I just looked into the source of the scripting plugin and notified you that there is no such function. You are actually encouraged to wait for more answers, if possible from a staff member.
.

Florin Calinescu


.

#5
Not exactly what you're looking but I remembered about this topic and the .Angle member variable if rotation is what you need.
.

.

#6
Oh... and also, manually (untested):
function VecToQuat(vec)
{
    local c1 = cos(vec.z * 0.5), c2 = cos(vec.y * 0.5),
          c3 = cos(vec.x * 0.5), s1 = sin(vec.z * 0.5),
          s2 = sin(vec.y * 0.5), s3 = sin(vec.x * 0.5);

    return Quaternion(
        (c1*c2*s3 - s1*s2*c3).tofloat(),
        (c1*s2*c3 + s1*c2*s3).tofloat(),
        (s1*c2*c3 - c1*s2*s3).tofloat(),
        (c1*c2*c3 + s1*s2*s3).tofloat()
    );
}

function onPlayerSpawn(player)
{
    local q = VecToQuat(player.Pos);
   
    print(format("%f, %f, %f, %f", q.x, q.y, q.z, q.w));
}
.

Florin Calinescu

#7
it works thanks 8)