Improve Rotation

Hello Guys,

I’m looking for a way to calculate a smooth rotation.

So far I got this:

Quaternion currentRotation = owner.getLocalRotation().clone();

owner.lookAt(targetPosition, Vector3f.UNIT_Y);

Quaternion targetRotation = owner.getLocalRotation();

Quaternion interpolatedRotation = targetRotation.slerp(currentRotation, targetRotation, 0.1f);


I am not satisfied with that solution: The performance is bad and it seems to me that it’s not that smooth. Any suggestions how to improve that piece of code?

You should probably add tpf here:


targetRotation.slerp(currentRotation, targetRotation, tpf*rotSpeed);


For performance you could maybe find the Vector3f direction the owner spatial is looking by subtracting targetPosition with owner position, and then use quaternion.lookat(direction,up) to get the targetRotation (direction is normalized in Quaternion, so no need to do that). lookat in class spatial does a lot of unnecessary calculations for your use.


public void lookAt(Vector3f position, Vector3f upVector) {

Vector3f worldTranslation = getWorldTranslation();

TempVars vars = TempVars.get();

Vector3f compVecA = vars.vect4;



getLocalRotation().lookAt(compVecA, upVector);




are you doing that all in an update() ? if so you should just calculate the beginning and end rotations once outside. Then in the update() use slerp() and setlocalrotation()