#### Archived

This topic is now archived and is closed to further replies.

# Please some one help me with orientation !!!

This topic is 6150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi Guys, my question is really easy, but i''m so dumb in math that i can''t figure it out !!! i have two objects in my game -enemy and player-, i want the enemy to be drawn to the orientation of the player ... that''s it ... i have the x,y,z positon of both the enemy and the player ... what i need is a function that would rotate the enemy so that when i draw it it would look like as if it was heading for the player -not moving to the right while it''s face is drawn to the back- ... please help me ... "If you don''''t like something, change it. If you can''''t change it, change the way you think about it!" "He who asks is a fool for five minutes, but he who does not ask remains a fool forever." "Imagination is more important than knowledge, for knowledge is limited while imagination embraces the entire world."(Einstein) "The normal teacher tells. The good teacher explains. The superior teacher demonstrates. The great teacher inspires."(William Arthur Ward)

##### Share on other sites
i can tell how much u like math from your signature

i didn''t get what you want exactly, but if u want to place the enemy infront of the player on a distance s.
you should have a vector of position for both. a heading vector for the player and the distance you want to place the enemy in.

player pos = vp;
distance = s;

FindEnemyPos()
{
vph_temp= Normalize(vph);
vph_temp= Scale(vph_temp, s);
}

hope that hits the spot ...

"The Railgun Master"
DaHeR

##### Share on other sites
Thanks daher ...

but maybe i was not clear enough ... what i want is that when i render the enemy -which is a tank- i want it to be drawn as if it's pointed at me ... you know what i mean ...

just imagine that the tank is moving towards me ... i want to rotate it so that it's turret is directed to me ... i just want the function to calculate the amount of degrees i have to rotate it ...

|
|   |  /
|
------------
|
x   |  -
|

where x is the player, and the | and - and / are the enemy ... you see the oriantation ....

thanks ...

Edited by - fixxxer on January 9, 2002 3:23:03 PM

##### Share on other sites
not to sound rude but if you goto gamedev.net''s forums in there math section i am sure someone there can give you some code to find angles between 2 points.. i have some code but its written in another programming language. if you wanna convert it let me now and i can post it. its only a handfull of lines.

http://www.lectersoft.com

##### Share on other sites
//what the hell here it is anyway
the values with the # are floats

function ca(px1#,py1#,px2#,py2#)

dx#=px2#-px1#
dy#=py2#-py1#

if dx#<0 then dx#=dx#*-1 : inc quadflag
if dx# <> 0
angle#=ATAN(dy#/dx#)
else
angle#=ATAN(dy#)
endif

if quadflag=1 then angle# = 180-angle#
if quadflag=2 then angle# = 360-angle#
if quadflag=3 then angle# = 180+angle#

if angle# > 0 then angle# =int(angle# +.50)

endfunction angle#

##### Share on other sites
dfawcett ... you are the greatest ... thanks dude ... you know earth is a great place to live because of people like you ...

thanks again ... i will try that ... but i think it''s what i need because it''s excatly what i thought of ...

thanks man ...

no prob

##### Share on other sites
This is how i convert .. why it doesn''t work ...

float dx = wx_pos - player.wx_pos;
float dy = wy_pos - player.wy_pos;

if (dx < 0)
{
dx = dx * -1;
}

if (dy < 0)
{
dy = dy * -1;
}

if (dx != 0)
cTanksceneroty = atan(dy/dx);
else
cTanksceneroty = atan(dy);

cTanksceneroty = 180-cTanksceneroty;
cTanksceneroty = 360-cTanksceneroty;
cTanksceneroty = 180+cTanksceneroty;

if (cTanksceneroty > 0)
cTanksceneroty = int(cTanksceneroty +.50);

glRotatef(cTanksceneroty,0,1.0f,0);

##### Share on other sites
Maybe there''s a problem with angle units.
I guess atan return the angle in radians, so you shouldn''t
add/substract 180 or 360 but PI or 2*PI, or convert the
result of atan().

And ya also have to make sure the unit is correct when
using glRotate !

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633287
• Total Posts
3011217
• ### Who's Online (See full list)

There are no registered users currently online

×