# Clamping a turret rotation

**URL:** <https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [February 22, 2023, 4:42am UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035 "2023-02-22T04:42:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakethesnake8691](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jakethesnake8691](https://forums.unrealengine.com/u/Jakethesnake8691)\
**Post date:** [February 22, 2023, 4:42am UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/1 "2023-02-22T04:42:54Z")

</div>

I am creating a game in which the turret needs to rotate 180 degrees. As of now, it rotates 360 degrees below ground. I attached the barrel to the sphere and just rotated the sphere to the effect i was looking for. Im using the player controller for my elevation control blueprint. This seems so ■■■■ simple but yet I’m stuck, please help. Im still learning but im a bit farther than beginner but still please dumb down any answers for me lol.

 ![Canon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/3/0/b3053b4471b39d79130fd770a42144a70c33611b.png)  
 ![CanonInPlace](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/0/970b1d1359b21e77232b2cb95271955a274b99cd.png)  
 ![Blueprints](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/2/59257ec5d93c92342500c8be4744c5278fd01e9c.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 22, 2023, 7:59am UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/2 "2023-02-22T07:59:59Z")

</div>

Have a look:

> [@Restrict Pawn's Rotation](https://forums.unrealengine.com/t/restrict-pawns-rotation/487856/3):
>
> Have a look at this one: Script to copy: [[Image from Gyazo]](https://gyazo.com/07facc8d174c94dd6103a641878c6929) Essentially, Dot Product is an answer to most angular issues. The yellow arrow indicates the turret’s front. Oh, and a TL is probably not the way to go about it unless you’re after something truly specific / unique / inflexible. Does not mesh well with target tracking in my head.

---

<div class="post-metadata">

**Author:** ![Jakethesnake8691](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jakethesnake8691](https://forums.unrealengine.com/u/Jakethesnake8691)\
**Post date:** [February 22, 2023, 6:26pm UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/3 "2023-02-22T18:26:20Z")

</div>

I saw that thread but could not figure out where all this code goes. Does this go in the canon as opposed to the game controller? Do i attach one of the nodes in this code to my existing code? Is there anyone that could explain why this works instead of a simple clamp?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 22, 2023, 6:38pm UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/4 "2023-02-22T18:38:28Z")

</div>

> where all this code goes.

In that case in the cannon since there were multiple.

In your case, you can:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/c/5/6c528c76494eb9324124d3ef806f41e162abc083.png)

or even like so with no variables:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/4/904ce7e75df749e39c34c78c8c5a33369b3e34c0.png)

* * *

There is a chance I do not fully understand the ask.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 22, 2023, 6:53pm UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/5 "2023-02-22T18:53:06Z")

</div>

> [@Everynone](#):
>
> There is a chance I do not fully understand the ask.

Perhaps this is what you’re after:

You could try:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/e/e4e04134dfcb9deeed459804fe42ac30b76b291c.jpeg)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/5/c/75c1b2eaed964e8d72fc9340df7382ec1f0ee90b.png)

If 180 is what you’re after, that’s the most _minimalistic_ I can think of.

* * *

And this maybe, too:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/5/4f59b44bac955150bb1347a735bb44791d2f4465.png)

Do tell if that helps at all. There’s probably half a dozen other ways, too.

---

<div class="post-metadata">

**Author:** ![Jakethesnake8691](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jakethesnake8691](https://forums.unrealengine.com/u/Jakethesnake8691)\
**Post date:** [February 23, 2023, 2:38am UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/6 "2023-02-23T02:38:14Z")

</div>

That is exactly what im after! I know i may seem like an idiot for getting stuck on something so simple but jesus this is racking my brain. Ok so essentially I want the barrel to rotate 180 degrees and not go into the ground. I tried the options above and still cannot get it to work. I am coding everything into the player controller, is that where im messing up? Essentially, i have set it up so that A and D move the barrel. The barrel is a child of the sphere so that I can rotate the sphere and the barrel moves with it. Please let me know if you need more info

---

<div class="post-metadata">

**Author:** ![Jakethesnake8691](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jakethesnake8691](https://forums.unrealengine.com/u/Jakethesnake8691)\
**Post date:** [February 23, 2023, 2:49am UTC](https://forums.unrealengine.com/t/clamping-a-turret-rotation/776035/7 "2023-02-23T02:49:37Z")

</div>

Ok so the most simplistic “Add Pitch Input” worked. I had to adjust the rotation of my canon to get the result i wanted but it worked! I still would like to figure out the other methods as well and maybe learn what I was doing wrong if anyone has the patience to help me understand lol. Also, sorry for the grammar mistakes, I usually type better but my brain in fried lol
