|
|
Angle between 2 entities
#137712
06/23/07 09:57
06/23/07 09:57
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
OP
Serious User
|
OP
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
Can someone tell me how can I calculate the angle (0-359) between 2 entities? Here is what I've done so far : Code:
dx = my.x - you.x; dy = my.y - you.y;
angle = fatan(dy,dx);
The angle always return +/- 90 only. Thanks.
|
|
|
Re: Angle between 2 entities
[Re: vlau]
#137713
06/23/07 10:42
06/23/07 10:42
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
User
|
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
vec_set(temp,you.x); vec_sub(temp,my.x); vec_to_angle(temp_angle,temp);
in this case temp_angle = angle to turn to look at second entity so it's different between entitys. This is what you want?
Never say never.
|
|
|
Re: Angle between 2 entities
[Re: tompo]
#137714
06/23/07 13:29
06/23/07 13:29
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
and if you insist on using ur own trigonometry you need to write an atan2 function which'll return between +-180 (unless you have the latest A7 private-beta). it just so happens i have one in my back-pocket (changed to work with c-script but untested): Code:
function atan2(var x,var y) { if(y==0) { return (90*sign(x)); } return(atan(x/y) - (180 * (y<0))); }
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Angle between 2 entities
[Re: JibbSmart]
#137716
06/23/07 13:42
06/23/07 13:42
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
this is what I use: Code:
vec_set(temp,Node_pos); vec_sub(temp,my.x); vec_to_angle(myang,temp); myang.pan = ang(myang.pan);
Last edited by Slin; 06/23/07 13:43.
|
|
|
Re: Angle between 2 entities
[Re: tompo]
#137719
06/23/07 14:21
06/23/07 14:21
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
OP
Serious User
|
OP
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
Ok, I think I got it : Code:
vec_diff(temp,you.x,my.x); vec_to_angle(angle,temp); angle %= 360;
Do you think so? if not please comment. Thank you all.
|
|
|
|