Raised This Month: $51 Target: $400
 12% 

Player facing direction angle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lifo
Junior Member
Join Date: Feb 2008
Old 08-20-2008 , 09:26   Player facing direction angle
Reply With Quote #1

I'm trying to figure out how to record the angle at which a player is facing at any given time. Or am I misunderstanding the purpose of GetVectorAngles? I'm using this value outside of the game, so using any other built in functions to do something with the vector is useless to me.

Code:
decl Float:vec[3], Float:ang[3];
GetClientEyeAngles(client, vec);
GetVectorAngles(vec, ang);
// ang[1] now contains an angle 0-359 degrees for 'y')
Essentially, I need the direction as a degree and not a vector.
Thanks.
__________________
lifo is offline
jheidt
Junior Member
Join Date: Aug 2008
Old 08-20-2008 , 10:00   Re: Player facing direction angle
Reply With Quote #2

The issue is, what is your definition of angle? In a 3d world, an angle vector is required because of the various degrees of freedom. If you want the 'top down player view angle', that is their yaw, this ignores any view angle along the up-down, and model rotational axis. The yaw is the Z axis in the hl2 sdk.

new Float:vAngles[3];
new Float:vec[3];

GetClientEyeAngles(client,vAngles);
GetAngleVectors(vAngles,vec,NULL_VECTOR,NULL_ VECTOR);
NormalizeVector(vec,vec);
#define IX_YAW 1
new Float:yaw = vec[IX_YAW];

yaw should now be a value between -359 and 359, where a negative value is a clockwise rotation.

I just wrote this off of the cuff, so mind me if its wrong, but the concept should be correct.
jheidt is offline
DiscoBBQ
Veteran Member
Join Date: Jan 2005
Location: Clemson, South Carolina
Old 08-20-2008 , 10:26   Re: Player facing direction angle
Reply With Quote #3

HL2 return's the player angles in y, z, x for pitch, yaw, roll; respectivly.
As shown here:
http://developer.valvesoftware.com/wiki/Angle

To return which way he is facing you get the 'z', the second parameter.

Code:
//Declare:
decl Float:Yaw, Float:Angles[3];
 
//Initialize:
GetClientAbsAngles(Client, Angles);
Yaw = Angles[1];
__________________
"Every man is guilty of all the good he did not do"
DiscoBBQ is offline
lifo
Junior Member
Join Date: Feb 2008
Old 08-20-2008 , 11:33   Re: Player facing direction angle
Reply With Quote #4

Thanks for the responses!

It looks like GetClientAbsAngles() is exactly what I needed. I've only tested it with bots (since I can't login to my server at the moment) and it seems the values are correct. I'm assume I can use the absolute value to obtain the current facing position, and maybe use the negative bit to determine if the player moved clockwise or not.

So simple, I originally overlooked that function since it didn't sound like it did what I needed.
__________________
lifo is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode