Rotate mesh to face camera..

Started by
21 comments, last by neurokaotix 20 years, 11 months ago
Specifically, here''s the code snippet that I was thinking would simply turn my Character object to face the next Route Point. I verified the Route Point and Object coordinates, they all checked out. The snippet is outside of the Frame() loop, if that makes any difference...


// rotate NPC to face its target point

float Direction = atan2(g_NPCObject[1].GetXPos() - Route[RoutePoint].XPos, g_NPCObject[1].GetZPos() - Route[RoutePoint].ZPos);

g_NPCObject[1].Rotate (0.0f, Direction, 0.0f);


(Direction in this case is 3.14159.)
Advertisement
Sorry, Jim. I''m a moron.

As it turns out, I was using your Yodan.x from your "Chars" example, which is apparently rotated. When I imported it into Milkshape and exported my own .x file, it was facing the route points properly.

Alas, you are da man... *bows reverently*
I confirmed this works in my engine also:

FLOAT fObjectYRotation = atan2(fObjectXPos - fMyXPos, fObjectZPos - fMyZPos);

Nice bit of code to have...

This topic is closed to new replies.

Advertisement