Raised This Month: $ Target: $400
 0% 

Get angle and direction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-01-2013 , 04:58   Get angle and direction
Reply With Quote #1

How do i get the different between my forward angle and the angle between me and my enemy?

[IMG]http://s8.************/uqu2nyuv9/Untitled.png[/IMG]

Last edited by GsiX; 12-01-2013 at 05:00.
GsiX is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 12-01-2013 , 10:40   Re: Get angle and direction
Reply With Quote #2

Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#pragma semicolon 1

stock Float:getAngleBetweenPlayerForwardAndTarget(client, target){

	decl Float:ang[3];
	GetClientEyeAngles(client, ang);
	decl Float:vec[3];
	decl Float:targetPos[3];
	GetClientAbsOrigin(client, vec);
	GetClientAbsOrigin(target, targetPos);
	decl Float:fwd[3];
	new Float:sineA = Sine(ang[0]);
	fwd[0] = sineA*Cosine(ang[1]);
	fwd[1] = sineA*Sine(ang[1]);
	fwd[2] = Cosine(ang[0]);
	vec[0] = targetPos[0] - vec[0];
	vec[1] = targetPos[1] - vec[1];
	vec[2] = targetPos[2] - vec[2];
	ScaleVector(vec, 1.0/SquareRoot(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]));
	return ArcCosine(vec[0]*fwd[0]+vec[1]*fwd[1]+vec[2]*fwd[2]);

}
ignore it —>
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 12-01-2013 at 10:44.
Bimbo1 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-01-2013 , 11:00   Re: Get angle and direction
Reply With Quote #3

Although I am pretty sure there is already a function for this, why care about the third component of the vectors? According to the diagram a 2d-approximation is sufficient.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-01-2013 , 11:17   Re: Get angle and direction
Reply With Quote #4

It always give me 1.6 in the different..
Maybe you forget "RadToDeg()". I need it in Degree. Million thanks man..

PHP Code:
stock Float:getAngleBetweenPlayerForwardAndTargetsubjecttarget )
{
    
decl Float:ang[3];
    
decl Float:vec[3];
    
decl Float:targetPos[3];
    
GetEntPropVectorsubjectProp_Data"m_angRotation"ang );
    
GetEntPropVectorsubjectProp_Send"m_vecOrigin"vec );
    
GetEntPropVectortargetProp_Send"m_vecOrigin"targetPos );
    
    
decl Float:fwd[3];
    new 
Float:sineA Sine(ang[0]);
    
fwd[0] = sineA*Cosine(ang[1]);
    
fwd[1] = sineA*Sine(ang[1]);
    
fwd[2] = Cosine(ang[0]);
    
vec[0] = targetPos[0] - vec[0];
    
vec[1] = targetPos[1] - vec[1];
    
vec[2] = targetPos[2] - vec[2];
    
ScaleVector(vec1.0/SquareRoot(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]));
    return 
ArcCosine(vec[0]*fwd[0]+vec[1]*fwd[1]+vec[2]*fwd[2]);


EDIT:
Quote:
Originally Posted by Dr. Greg House View Post
Although I am pretty sure there is already a function for this, why care about the third component of the vectors? According to the diagram a 2d-approximation is sufficient.
Woops.. didn't see your post..
Anyway, my math is very poor.. i dont know what you talking about..

Last edited by GsiX; 12-01-2013 at 11:19.
GsiX is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-01-2013 , 11:40   Re: Get angle and direction
Reply With Quote #5

Quote:
Originally Posted by GsiX View Post
Woops.. didn't see your post..
Anyway, my math is very poor.. i dont know what you talking about..
He's saying that the up/down component of the vector doesn't need to be looked at, since you're only concerned with the left/right angles. Looking up or down won't change your x angle.
__________________
11530 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-01-2013 , 11:43   Re: Get angle and direction
Reply With Quote #6

Quote:
Originally Posted by 11530 View Post
He's saying that the up/down component of the vector doesn't need to be looked at, since you're only concerned with the left/right angles. Looking up or down won't change your x angle.
Yes.. that correct.. i only need left/right..
But i will appreciate if it always calculate in Counter Clock Wise (if by mean possible). Easy for me to do the next steps.
GsiX is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 12-01-2013 , 11:59   Re: Get angle and direction
Reply With Quote #7

there are functions for a lot of things, but i like to optmize things when i can. also, it's just a diagram, it's supposed to be simple. that doesn't exclude the possibility of he wanting it in 3d. well, it's not hard to make it 2d, though.
what do you mean by calculate in counter clock wise?
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 12-01-2013 at 12:00.
Bimbo1 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-01-2013 , 12:08   Re: Get angle and direction
Reply With Quote #8

Nvm.. i dont think its possible..
So may you get the calculation for me then..?
GsiX is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 12-01-2013 , 12:19   Re: Get angle and direction
Reply With Quote #9

what's not possible and calculate what?
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-01-2013 , 12:27   Re: Get angle and direction
Reply With Quote #10

To calculate the angle result in CCW direction. I mean from 0 degree to 360 degree.. or at least 180 degree.

EDIT: I dont actually know how the degree work so if it cant happen just ignore it.. simply some degree number will fulfill my need..

Last edited by GsiX; 12-01-2013 at 12:30.
GsiX 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 23:20.


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