Please some one help me with orientation !!!

Started by
12 comments, last by Fixxxer 22 years, 3 months ago
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)
"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)
Advertisement
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;
player heading = vph;
distance = s;

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

hope that hits the spot ...

"The Railgun Master"
DaHeR
____________________________________MSN | AIM | YIM | ICQ
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
"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)
Please help ...
"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)
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
http://www.lectersoft.com
//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#

quadflag=0
if dx#<0 then dx#=dx#*-1 : inc quadflag
if dy# < 0 then dy#=dy#*-1 : quadflag= quadflag+2
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#
http://www.lectersoft.com
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 ...
"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)
no prob
http://www.lectersoft.com
This is how i convert .. why it doesn''t work ...

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

int quadflag=0;

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

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

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

if (quadflag == 1)
cTanksceneroty = 180-cTanksceneroty;
if (quadflag == 2)
cTanksceneroty = 360-cTanksceneroty;
if (quadflag == 3)
cTanksceneroty = 180+cTanksceneroty;

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

glRotatef(cTanksceneroty,0,1.0f,0);
"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)
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 !
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)

This topic is closed to new replies.

Advertisement