AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Get angle and direction (https://forums.alliedmods.net/showthread.php?t=230737)

GsiX 12-01-2013 04:58

Get angle and direction
 
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]

Bimbo1 12-01-2013 10:40

Re: Get angle and direction
 
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 —>http://3.bp.blogspot.com/-x6yYPE5Tt1...7_mYq9sogW.gif

Dr. Greg House 12-01-2013 11:00

Re: Get angle and direction
 
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.

GsiX 12-01-2013 11:17

Re: Get angle and direction
 
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 (Post 2067467)
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..

11530 12-01-2013 11:40

Re: Get angle and direction
 
Quote:

Originally Posted by GsiX (Post 2067472)
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.

GsiX 12-01-2013 11:43

Re: Get angle and direction
 
Quote:

Originally Posted by 11530 (Post 2067482)
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.

Bimbo1 12-01-2013 11:59

Re: Get angle and direction
 
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?

GsiX 12-01-2013 12:08

Re: Get angle and direction
 
Nvm.. i dont think its possible..
So may you get the calculation for me then..?

Bimbo1 12-01-2013 12:19

Re: Get angle and direction
 
what's not possible and calculate what?

GsiX 12-01-2013 12:27

Re: Get angle and direction
 
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..


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

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