# Limiting rotation of component on moving actor

**URL:** <https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [January 3, 2025, 12:24pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492 "2025-01-03T12:24:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zippyo3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zippyo3](https://forums.unrealengine.com/u/Zippyo3)\
**Post date:** [January 3, 2025, 12:24pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492/1 "2025-01-03T12:24:18Z")

</div>

Hello,

Need a little advice on limiting the rotation of a component on a moving actor.

I have a vehicle, with a turret on the right side. As the player moves around the world, it detects targets and turns the turret to face and shoot at the targets. Currently, I get the Look at the rotation of the target and the turret pivot, I rotate the gun and fire. I have used a clamp angle node to limit the Y (Pitch) angle so that the turret doesn’t aim too high/too low and this works well.

I want to limit the turret’s rotation to 180 degrees on the Z (Yaw) axis (so it cannot shoot through itself); however, as the vehicle moves, a clamp value won’t work here as the Z value is continuously changing with vehicle rotation.

What is the best approach to limiting the rotation of the turret to 180 degrees from its relative position?

Current attempted method

 ![limitrotation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/d/f5dc166d3b412c875dbbc5c28618e8b725cfd767.png)

---

<div class="post-metadata">

**Author:** ![VisAgilis](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/visagilis/32/891043_2.png) [@VisAgilis](https://forums.unrealengine.com/u/VisAgilis)\
**Post date:** [January 3, 2025, 12:36pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492/2 "2025-01-03T12:36:36Z")

</div>

> [@Zippyo3](#):
>
> as the vehicle moves, a clamp value won’t work here as the Z value is continuously changing with vehicle rotation

You can get the parent actor’s rotation, break the return value, add to / subtract from the z component and use that value instead.

---

<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:** [January 3, 2025, 12:55pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492/3 "2025-01-03T12:55:35Z")

</div>

if you want to use `World Rotation` for the turret (which you should not, this is a job for `Relative Rotation`, but it can be made to work), the `Min` & `Max` should also be derived from the world rotation of the parent vehicle.

* * *

> this is a job for `Relative Rotation`

Here’s an example of angle locked relative rotation with transforms, derived from the `Look at Rotation` node:

> [@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:** ![Zippyo3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zippyo3](https://forums.unrealengine.com/u/Zippyo3)\
**Post date:** [January 3, 2025, 1:16pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492/4 "2025-01-03T13:16:23Z")

</div>

That’s the ticket, always like learning more about Math 😃

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [February 2, 2025, 1:17pm UTC](https://forums.unrealengine.com/t/limiting-rotation-of-component-on-moving-actor/2257492/5 "2025-02-02T13:17:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
