- Home /
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
Answer by Maurice_B · Feb 07, 2015 at 09:35 AM
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.
Answer by hav_ngs_ru · Feb 07, 2015 at 12:01 AM
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).
could you give a code example.
As I said before I don't get quaternions.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182700im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help clamping a Rotation 1 Answer
How to clamp Lookat? 2 Answers
Clamping a wrapping rotation. 6 Answers