How to make transform smoothly watch another transform? (Solved)

I’m making simple helicopter AI that flies to the waypoint. When it gets close enough, it receives new waypoint at random location. I want helicopter to look at waypoint smoothly. I tried using this:

transform.forward = Vector3.Lerp(transform.forward, Waypoint, turningSpeed * Time.deltaTime);

But it didn’t work - instead of smoothly turn to look at waypoint helicopter instantly starts tracking it. How do i make heli smoothly turn to look at waypoint?

That’s not the correct way to use Lerp. It hurts that the examples in Unity’s documentation are so poor at explaining how to use it. You need to move that third parameter from 0 to 1 over the course of the interpolation (across multiple frames). You also need to keep the starting direction constant across all of the calls. So you do something like this:

// Number of seconds it takes to smoothly look
float smoothLookDuration = 2f;

void Update() {
  if (something) {

    Vector3 startFacing = transform.forward;
    Vector3 desiredFacing = /* however you get this */
    StartCoroutine(SmoothlyFace(startFacing, desiredFacing));
  }
}

IEnumerator SmoothlyFace(Vector3 start, Vector3 target) {
  float t = 0;
  while (t < 1) {
    t += Time.deltaTime / smoothLookDuration;
    transform.forward = Vector3.Lerp(start, target, t);
  }
}

Lerp is good for doing an operation that takes a predfined amount of time. If you want to specify instead the speed at which the thing rotates, I recommend Quaternion.RotateTowards instead. That would look something like this:

void Update() {
  Quaternion targetRotation = /* however you get the target rotation */

  transform.rotation = Quaternion.RotateTowards(transform.rotation, targtRotation, rotationSpeed * Time.deltaTime);
}

I fixed it - instead of multiplying Time.deltaTime on turningSpeed i tried dividing it by turningSpeed. It worked

Thanks, PreatorBlue