-1

I count the angle at which the drone needs to turn so that it looks at the player. I figured it out, but the drone can change its targets and during the target change it abruptly changes its rotation. How can this transition be made smooth?

var finalAngle = Vector3.Angle(targetPosition - _droneTransform.localPosition, _droneTransform.forward);
_droneTransform.localEulerAngles = new Vector3(_finalPitch, finalAngle, _finalRoll);
Hatemsla
  • 45
  • 5

1 Answers1

1

You can use Vector3.RotateTowards() https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html

In this scenario to prevent the issue of Gimbal Lock I'd suggest pre calculation the quaternion rotations and use Quaternion.RotateTowards() https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html

Precalculate the rotations using Quaternion.Euler() https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html

The quickest way to get a rotation that looks at a target is by using Quaternion.LookRotation() https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html

CBX_MG
  • 93
  • 8