I want to make a smooth LookAt, I mean, rotating over time the object towards a 3D point.
The smoothly interpolation (see exemple below) is not what I want in my case because the object rotating is also moving at the same time (causing the object not rotating towards the 3D point but a specific orientation):
var percent = this.time / this.movementDuration;
//Use slerp to smoothly interpolate between two angles
//http://developer.playcanvas.com/en/api/pc.Quat.html#slerp
angle.slerp(fromRotation, toRotation, percent );
This looks slightly off compared to Unity’s. The value being passed in Unity’s is the number of degrees to rotate by where the above version is rotating by a percentage of what’s remaining.
This would mean that as the entity gets closer to the target rotation, the speed of the rotation gets slower.
Untested code below but this was how I saw the Unity code:
OrbitCamera.prototype.rotateTowards = function (quat_a, quat_b, degreesDelta) {
var angle = this.quatAngle(quat_a, quat_b);
if (angle === 0)
{
return quat_b;
}
return new pc.Quat().slerp(quat_a, quat_b, Math.min(1, degreesDelta / angle));
};
True, the speed of the rotation was getting slower when getting closer to the target.
I solved this by not setting the original_rotation variable in update but only when the animation started.
In my case, I used percentage for a specific reason but I think your solution will work too.
I’m happy to document this here and contribute to the playcanvas community.
Ok, cool, thanks. I’ll give it a shot. I dropped your code into a new script and it threw some errors. Maybe I’m missing something? Do you have a sample project with it up and running? Thanks