Jump to content
  • Advertisement

Archived

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

GekkoCube

making a character always face an object.

This topic is 5467 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

for example, i want my player character to always face the enemy. i just need somebody to check if im doing this right or wrong. heres what i have so far...
position player.pos();
position enemy.pos();
position dir = enemy - player;

float angle = atan2f(dir.x, dir.y);
angle = 90.0f - angle;

rotateZ(angle);

Share this post


Link to post
Share on other sites
Advertisement
I think that you mean : Billboarding.

With that, your sprite, polygon, ... will always facing the camera.

So, for an example check on my website for a simple demo.




========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/

Share this post


Link to post
Share on other sites
The math looks good, you should be able to use atan2f(dir.y,dir.x) and forget the next step of =90-angle.

Though technicaly not required, I think it would be wise to differentiate between points and vectors, your position datatype is being used as both here, and that can lead to confusion and even logical errors.

(I don''t believe he actually means billboarding. Though the concept of billboarding can be used to achieve what he wants.)

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!