# How to clamp Pitch after AddLocalRotation()?

**URL:** <https://forums.unrealengine.com/t/how-to-clamp-pitch-after-addlocalrotation/483514>\
**Category:** Community & Industry Discussion\
**Tags:** relative, world, rotation, unreal-engine, clamp, local, question\
**Created:** [May 17, 2021, 2:50pm UTC](https://forums.unrealengine.com/t/how-to-clamp-pitch-after-addlocalrotation/483514 "2021-05-17T14:50:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wilricknl](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wilricknl](https://forums.unrealengine.com/u/wilricknl)\
**Post date:** [May 17, 2021, 2:50pm UTC](https://forums.unrealengine.com/t/how-to-clamp-pitch-after-addlocalrotation/483514/1 "2021-05-17T14:50:53Z")

</div>

SpringArm-\>AddLocalRotation({ static\_cast(RotatePitchAxis \* 30.0f \* DeltaTime), 0.0f, 0.0f });

I am changing the local Pitch rotation, but afterwards I wish to make sure the pitch clamps between a minimum value and maximum value. I tried clamping the relative rotation as follows, but this messes up yaw and roll. I only want to make sure the Pitch stays between two values and not touch the yaw and roll.

```
auto Rotation = SpringArm->GetComponentRotation();
Rotation.Pitch = FMath::Clamp(Rotation.Pitch, SpringArmMinPitch, SpringArmMaxPitch);
SpringArm->SetRelativeRotation(Rotation);

```

Does anyone have a suggestions on clamping the pitch?

---

<div class="post-metadata">

**Author:** ![Fraps2020](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fraps2020/32/460865_2.png) [@Fraps2020](https://forums.unrealengine.com/u/Fraps2020)\
**Post date:** [May 17, 2021, 3:21pm UTC](https://forums.unrealengine.com/t/how-to-clamp-pitch-after-addlocalrotation/483514/2 "2021-05-17T15:21:18Z")

</div>

Hi wilricknl,

you’re messing things up because GetComponentRotation retrieves rotation in world space whereas SetRelativeRotation sets it in local space. Depending on whether you want to clamp your local or absolute pitch you’ll want to uniform your function calls – by either using GetRelativeRotation or SetWorldRotation.

hope that helps!

f

---

<div class="post-metadata">

**Author:** ![wilricknl](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wilricknl](https://forums.unrealengine.com/u/wilricknl)\
**Post date:** [May 17, 2021, 3:38pm UTC](https://forums.unrealengine.com/t/how-to-clamp-pitch-after-addlocalrotation/483514/3 "2021-05-17T15:38:56Z")

</div>

Thanks for the clear explanation. Replacing SpringArm-\>GetComponentRotation() with SpringArm-\>GetRelativeRotation() works as intented.
