# Limit SpringArm Rotation

**URL:** <https://forums.unrealengine.com/t/limit-springarm-rotation/457444>\
**Category:** Cinematics & Media\
**Tags:** rotation, spring-arm, springarm, unreal-engine, question, CPP\
**Created:** [October 23, 2019, 11:29pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444 "2019-10-23T23:29:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 23, 2019, 11:29pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/1 "2019-10-23T23:29:57Z")

</div>

Hello,  
Does anybody know how to limit the Rotation of a SpringArm Component in C++ code?

My current approach is like this:

```
FRotator currentRotation = CameraBoom->GetSocketRotation(CameraBoom->SocketName);
if (currentRotation.Pitch + event.Value > 60 || currentRotation.Pitch + event.Value < -50)
    break;
AddControllerPitchInput(event.Value);

```

but for some reason the Camera snaps to a 90° angle when I reach the limit instead of just stopping.

---

<div class="post-metadata">

**Author:** ![Unearthlywhales](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Unearthlywhales](https://forums.unrealengine.com/u/Unearthlywhales)\
**Post date:** [October 24, 2019, 12:15am UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/2 "2019-10-24T00:15:12Z")

</div>

I’m not the biggest C++ guy, (still trying to put in the time) but this sounds like a clamp would be a good solution for it?

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 24, 2019, 6:11am UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/3 "2019-10-24T06:11:48Z")

</div>

Yeah I tried that before but it gives the same result. I’m not really getting what is happening 😕

---

<div class="post-metadata">

**Author:** ![SebaSopp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SebaSopp](https://forums.unrealengine.com/u/SebaSopp)\
**Post date:** [October 24, 2019, 2:09pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/4 "2019-10-24T14:09:56Z")

</div>

Is this running in a loop or why are you using “break” instead of “return”?

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 24, 2019, 2:24pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/5 "2019-10-24T14:24:40Z")

</div>

I have a custom PlayerController class which sends events to my Character class.  
The break is for a switch statement on the event type.

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [October 24, 2019, 9:34pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/6 "2019-10-24T21:34:41Z")

</div>

could it be gimbal lock?

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 24, 2019, 9:44pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/7 "2019-10-24T21:44:26Z")

</div>

what do you mean?

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [October 24, 2019, 10:09pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/8 "2019-10-24T22:09:22Z")

</div>

if more than on axis is 90 degrees at the same time so they line up with each other, it will get them confused from that point on.

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 24, 2019, 10:20pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/9 "2019-10-24T22:20:37Z")

</div>

Oh I didn’t know that. But shouldn’t my code prevent exactly that?

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [October 25, 2019, 2:42am UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/10 "2019-10-25T02:42:44Z")

</div>

Maybe, except you are adding the combined values to the current rotation. I think you want to SET it to the combined values or just add the event value. since you are adding to what is already there you can easily go past those numbers.

---

<div class="post-metadata">

**Author:** ![Reuben\_Ward](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Reuben\_Ward](https://forums.unrealengine.com/u/Reuben_Ward)\
**Post date:** [October 25, 2019, 5:05am UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/11 "2019-10-25T05:05:36Z")

</div>

You’ll want to look at the APlayerCameraManager class. It contains properties for clamping camera rotation.

See the documentation [here.](https://docs.unrealengine.com/en-US/API/Runtime/Engine/Camera/APlayerCameraManager/index.html)

You’ll want to create a blueprint or C++ class extending APlayerCameraManager and set the clamp values. From there, open your Player controller up and set the PlayerCameraManager variable to your custom player camera manager.

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 25, 2019, 12:57pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/12 "2019-10-25T12:57:59Z")

</div>

I figured that something with my calculations was wrong so it was no gimbal lock. But I’m going with ReubenWards answer which works for me. Thanks for your replies though 🙂

---

<div class="post-metadata">

**Author:** ![darman96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darman96](https://forums.unrealengine.com/u/darman96)\
**Post date:** [October 25, 2019, 12:59pm UTC](https://forums.unrealengine.com/t/limit-springarm-rotation/457444/13 "2019-10-25T12:59:35Z")

</div>

Thanks. That works for me. I took a brief look at the camera manager before but didn’t quite understand how it works.
