Archived

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

GekkoCube

making a character always face an object.

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
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