Raised This Month: $ Target: $400
 0% 

Get the angle of a line between two origins


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-20-2009 , 22:01   Re: Get the angle of a line between two origins
Reply With Quote #5

Quote:
Originally Posted by stupok View Post
Code:
new Float:fOrigin1[3]
new Float:fOrigin2[3]
new Float:fVector[3]
new Float:fAngle[3]

xs_vec_sub(fOrigin2, fOrigin1, fVector)
vector_to_angle(fVector, fAngle)
xs_vec_angle is for vectors, not origins
Thanks stupok & exolent. +karma to both

I put it into a function to return 89 when aiming straight up, 0 when aiming perfectly straight, and -89 aiming straight down (when the aiming players origin is passed as first origin param). For anyone else that needs this:

PHP Code:
FloatGetAngleOrigins(Float:fOrigin1[3], Float:fOrigin2[3] )
{
    new 
Float:fVector[3];
    new 
Float:fAngle[3];
    new 
Float:fLineAngle;
    
    
xs_vec_sub(fOrigin2fOrigin1fVector);
    
vector_to_angle(fVectorfAngle);
    
    if( 
fAngle[0] > 90.0 )
        
fLineAngle = -(360.0 fAngle[0]);
    else
        
fLineAngle fAngle[0];
    
    return 
fLineAngle;

To see it in action:
PHP Code:
new Float:fOrigin1[3];
new 
Float:fOrigin2[3];
pevid pev_originfOrigin1 );
fm_get_aim_origin(idfOrigin2 );
        
client_print(id,print_chat,"Angle of line from you to where aiming: %f" GetAngleOrigins(fOrigin1,fOrigin2) ); 
__________________

Last edited by Bugsy; 02-21-2009 at 00:56.
Bugsy is offline
 



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 17:07.


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