Turret rotation clamp.

I have a turret and I can get it to look at the target with LookAt however I want to limit its rotation so that it can move within a 140’ cone. I have tried using LookAt then clamping each rotation axis within the bounds. This did not work. By the way, I don’t understand quaternians so if they are used could you explain.

Thanks Maurice

140` cone means that angle between direction turret looks at and direction turret initially looks at is less than 140’.

in other words, if you have turretBody and turretHead gameObjects, and they are rotated the same, then you could just check Quaternion.Angle(body.transform.rotation, head.transform.rotation) - it will give you an angle between head original rotation and the head rotation at the time. and you could not rotate head to the target if angle is more than 140’ (and apply a little reverse FromToRotation to rotate head a little in original direction to enable to-target-rotation in next frame).

I found out how to do it(Without Quaternions). I added an extra child next to the barrel and applied the lookat to that. I then set the barrels rotation to a clamped version of the child I had made.

I hope that helps anyone with the same problem.