i have some basic question i'm stuck with for hours by now. I searched the forum, but had no luck...
I just want to get the Angle between two sceneNodes so i can rotate one to face the other in a smooth way.
I found the following to face a target scene node (unitNode==SceneNode of player, target==SceneNode of target):
Code: Select all
void CBaseUnit::faceTarget() {
vector3df diff = target->getPosition() - unitNode->getPosition();
unitNode->setRotation(diff.getHorizontalAngle());
unitNode->updateAbsolutePosition();
};
Code: Select all
void CBaseUnit::turnLeft(unsigned int deltaTime) {
matrix4 m = unitNode->getRelativeTransformation();
matrix4 n;
n.setRotationDegrees(vector3df(0, (-speed * rotationSpeed * deltaTime), 0));
m *= n;
unitNode->setRotation(m.getRotationDegrees());
}
Code: Select all
void CBaseUnit::turnRight(unsigned int deltaTime) {
matrix4 m = unitNode->getRelativeTransformation();
matrix4 n;
n.setRotationDegrees(vector3df(0, (speed * rotationSpeed * deltaTime), 0));
m *= n;
unitNode->setRotation(m.getRotationDegrees());
}
Any help would be great!
Thanks,
Andreas