I have a turret object which is made of several parts, one rotates left and right, the other rotates up and down and is also a child of the left/right object. The turrets are attached to objects that move around, this is the only script I found that allows them to look at a target correctly without being completely misaligned:
public Transform horizontalAxis;
public Transform verticalAxis;
private Transform currentTarget;
private void RotateTurret(){
Vector3 targetDir = verticalAxis.InverseTransformPoint (currentTarget.position);
targetDir.y = 0;
targetDir = verticalAxis.TransformPoint (targetDir);
verticalAxis.LookAt (targetDir, verticalAxis.up);
horizontalAxis.LookAt (currentTarget, horizontalAxis.up);
}
The only issue is that they snap to the target immediately, my goal here is to make the turret smoothly turn towards the target using Quaternion.Slerp for example. I tried implementing a Slerp/Lerp into the rotate method but it seemed to break everything.
Any ideas how I can smoothly turn towards the turrets target?