I have a turret that is supposed to rotate toward it’s target if it is in view. This is what I have for the rotation code:
Vector3 targetPoint = target.root.position;
Quaternion targetRotation = Quaternion.LookRotation (targetPoint - (rotatingTransformY.transform.position), Vector3.up);
rotatingTransformY.transform.rotation = Quaternion.RotateTowards(rotatingTransformY.transform.rotation, targetRotation, 40.0f * Time.smoothDeltaTime);
//make sure it only rotates on it's Y axis
rotatingTransformY.transform.eulerAngles = new Vector3(0, rotatingTransformY.transform.eulerAngles.y, 0);
The problem I am having with this is that the closer the turret gets to looking at the target, the rotation starts slowing down. This is an “Anti air turret” that is supposed to be able to take down flying vehicles in my game, but it isn’t working that well, for example, if I fly by the turret with my helicopter, the turret is always lagging just behind the helicopter (probably due to RotateTowards lerp funcitonality), so it never catches up to the helicopter game object. I have tried to find a solution to this, but pretty much everywhere I’ve looked, there’s always the “solved” answer by using Lerp, Slerp etc… but that is not what I need. I need it to rotate towards the target at a constant speed.
Does anyone have any solutions to this?