# Adjusting Camera Pitch limit from blueprint to C++ translation correct?

**URL:** <https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, CPP, question\
**Created:** [May 2, 2022, 3:31pm UTC](https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774 "2022-05-02T15:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 2, 2022, 3:31pm UTC](https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774/1 "2022-05-02T15:31:27Z")

</div>

I am trying to limit Camera Pitch Scale in according to character pose state.  
Implementation in bp is working fine, but in C++ the character is always looking to the sky.

 ![image_2022-05-02_202824850](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/e/68ead7f94af1d58e5ba189db0e5ae694c414dbe6.png)

C++ version:

```auto
//If the limit is currently exceeded, set the boundary value
	if (!(GetControlRotation().Pitch > LocBottomValue) || !(GetControlRotation().Pitch < LocTopValue))
	{
		if ((abs(rot.Pitch - LocTopValue)) < (abs(rot.Pitch - LocBottomValue)))
		{
            FRotator rot = GetControlRotation();
			rot.Pitch = LocTopValue;
			MyControllerRef->SetControlRotation (rot);
		}
		else
		{
			FRotator rot = GetControlRotation();
			rot.Pitch = LocBottomValue;
			MyControllerRef->SetControlRotation(rot);
		}
	}

```

---

<div class="post-metadata">

**Author:** ![splodginald](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@splodginald](https://forums.unrealengine.com/u/splodginald)\
**Post date:** [May 2, 2022, 4:03pm UTC](https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774/2 "2022-05-02T16:03:43Z")

</div>

You have an extra NOT (!) operator in your first if and The single NOT operator should be outside the boolean OR (||) expression contained in parenthesis:

`if (!((GetControlRotation().Pitch > LocBottomValue) || (GetControlRotation().Pitch < LocTopValue)))`

Because of operator precedence, you can remove some parenthesis and condense to:

`if (!(GetControlRotation().Pitch > LocBottomValue || GetControlRotation().Pitch < LocTopValue))`

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 2, 2022, 4:24pm UTC](https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774/3 "2022-05-02T16:24:26Z")

</div>

Thank You for helping to optimize the code, Thank You very much.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 2, 2022, 5:14pm UTC](https://forums.unrealengine.com/t/adjusting-camera-pitch-limit-from-blueprint-to-c-translation-correct/546774/4 "2022-05-02T17:14:35Z")

</div>

Thank You for help, You just solved my problem… Thank You very much.
