Advertisement

RTS

Started by June 23, 2000 06:17 PM
4 comments, last by Wes Henwood 24 years, 4 months ago
In an RTS, what is a good way to make units face the appropriate direction? Suppose you have a tank at location 300,300 and you click at 250,300 for the tank to move there. Does anyone know of a way to calculate which angle the unit should face to move in that direction?
First calc the difference
[250,300] - [300,300] = [-50, 0]

P/\             P = destination/  \           O = origin/y   \         a = angle/      \       y = y difference/__x__a_/O     x = x difference 


tan(a) = y/x= 0 / -50 = 0
-1
tan = a

oh well something like that

Advertisement
Jrz''s got the idea. Just to try to clarify:

angleToFace = arctan( (destinationY - locationY)/(destinationX - locationX) )

Happy coding.


while( strcmp(reply,flame) )    followThread();


random-nomad
Ok, I have a method worked out to determine the correct direction to face. It requires inverse tangents, but I cannot find a function in the C libraries to caclulate an inverse tangent. Does anyone know of such a function? or how to calcuated an inverse tangent?

There''s different ways to do this. The easiest would be to just
use the standard c atan() or atan2() which you should find in math.h For a more info, check this.

random-nomad
Well,
I am doing a RTS.....and is working...

so for my tank = terestrial unit i first calculate path up to target then i calculate heading each time it cahnges points from my path vector...

for heading i have only 32 options (think u need more?) and i choose them from a Look Up table based on dx/dy and some normalization

one last thing dont forget u have to move gently from one heading to the other going through all intermediate headings

Ohs.. PS for Aerial units jus calculate it at the beginning from dx/dy

Hope this helps

Bogdan
obysoft

This topic is closed to new replies.

Advertisement