Author Topic: Function to determine direction player facing  (Read 677 times)

I need a function to figure out whether a player is facing north, east, south or west and then return 0, 1, 2 or 3. Also, if you could add in what this would be co-ordinate wise, that would be helpful too. Thanks

I am not that good at trigonometry and thus can't help you find the current direction, but I could reference what the different direction rotations are.

0North1 0 0 0
1East0 0 1 90
2South0 0 1 180
3West0 0 -1 90
« Last Edit: January 04, 2012, 12:52:07 AM by Port »

this is from Client_BuildBot, so it is client sided code

Code: [Select]

function getplayerdirection()
{
if(isObject(%p = serverconnection.getcontrolobject()))
{
%va = getword(%p.getforwardvector(),0);
%vb = getword(%p.getforwardvector(),1);

if(mabs(%va) > mabs(%vb))
{
if(%va > 0)
return 0;
else
return 2;
}
else
{
if(%vb > 0)
return 1;
else
return 3;
}
}
else
return 4;
}

0 = east