Hey guys, I’m using the following code to rotate an enemy model to face the player model.
It’s the humble beginning of a simple steering behaviour.
Generally it’s working, but the orientation seems to flicker occasionally, which visually looks like a 90 degree error in orientation. Any ideas what the source of the numerical instability might be?
// Get the current facing direction (had to flip sign to suit model) Vector3 currentDir = - GetNode()->GetWorldDirection(); // Get the desired new direction Vector3 newDir = (target_->GetNode()->GetWorldPosition() - GetNode()->GetWorldPosition()).Normalized(); // Compute the angle between current and new directions float angle = currentDir.Angle(newDir); // Construct our quaternion to rotate around world up axis by our angle Quaternion q(angle, Vector3(0,1,0)); // Apply rotation GetNode()->Rotate(q, TS_WORLD);