• Pingback: ()

  • Alan Wang

    Is it possible to combine smoothdamp with transform.LookAt?

    the current transform.LookAt on the camera locks the camera position to the character, creating a “stiff” camera movement. 🙁

    • jtyma

      Hi! If you want to use SmoothDamp you must pay attention to rotation discontinuity. Rotation is in range from 0 to 360 degrees so if you exceed these limits you will see something strange in your camera’s behaviour 😉

      To deal with it you can use SmoothDampAngle function instead and smooth each angle separately. We prepared a simple scene to show you that this approach works fine: http://cloud.aliasinggames.com/data/public/f5ea0d

      You can also use quaternion’s Slerp function:

      void Update()
      var targetRotation = Quaternion.LookRotation(player.transform.position - transform.position);
      transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);

      but remember this is an invalid way to use lerps functions which was described here: http://devblog.aliasinggames.com/how-to-lerp-properly/ We think that the first way is the best.

      Best regards!

  • Alkis Tsapanidis

    I know that this is slightly necro, but you can ILSpy the implementation of SmoothDamp and any other function implemented in managed code in Unity, if you are curious about the actual maths behind it.