Right now I am working on an AI scripts and currently have the bot lookat a target once he sees it. The problem is that its done instantly. I would like for it to take a few seconds that would be the reaction time of th ai. Ive used smoothdamp and seen there is a smoothdampangle but wasnt sure how to use it for this purpose. Anyone know how I could acomplish this?
You can use damping with Slerp. Instead of using LookAt with the transform, work with the Transform’s rotation, which is a Quaternion. Use the method SetLookRotation - it will return a quaternion / rotation that’s you’re target - where you want to look. Then take your current rotation (transform.rotation) and this target rotation, and plug them into Slerp, and that’s where you can do smooth damping.
Using @Julien-Lynge’s answer, I came up with this:
public Transform Target;
public float RotateSmoothTime = 0.1f;
private float AngularVelocity = 0.0f;
// ...
var target_rot = Quaternion.LookRotation(Target.position - transform.position);
var delta = Quaternion.Angle(transform.rotation, target_rot);
if (delta > 0.0f)
{
var t = Mathf.SmoothDampAngle(delta, 0.0f, ref AngularVelocity, RotateSmoothTime);
t = 1.0f - t/delta;
transform.rotation = Quaternion.Slerp(transform.rotation, target_rot, t);
}