Archived

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

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

• Forum Statistics

• Total Topics
628377
• Total Posts
2982326

• 10
• 9
• 14
• 24
• 11