So Lets say you have an NPC. The player talks to that NPC, the NPC needs to turn around so that he is facing the player, and appears to be talking to him.
I stumped with making a node face another node, but eventually I figured it out:
Enemy is a an AnimatedMeshSceneNode, and So is Player. I'm assuming you've declared these as global.
Code: Select all
vector3df eneloc = enemy->getPosition(); // Enemy location
vector3df plyloc = player->getPosition(); // Player location
enemy->updateAbsolutePosition();
core::vector3df vect = plyloc - enemy->getAbsolutePosition();
vect.Y = vect.getHorizontalAngle().Y;
enemy->setRotation(vector3df(0, vect.Y, 0));
And There You have it!
I hope this will be useful to someone.
EDIT:
Oops, I just realized someone had already posted another way to do this.
But I assure you my method is Very efficient, uses less lines of code, and far more easier to understand than any other method I've seen.
EDIT2:
Updated due to complaints