Jump to content
  • Advertisement

Archived

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

Wes Henwood

RTS

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!