Why is clamping the camera's pitch input causing weird behavior?

I’m trying to limit the camera’s pitch within a range of [20,-45], so I went into the function that executes whenever the LookUp axis fires, and clamped the original value to fall within the rotation range I want:

//    Cast<APawn>(this)->AddControllerPitchInput(Rate); //Old code
	Cast<APawn>(this)->AddControllerPitchInput(FMath::Clamp(Rate,20.0f, -45.0f)); //New, clamped version

This results in super-weird camera behavior, the boom rotates the camera to face almost straight down and never moves it. I assume that means I’m clamping the wrong value, but if I can’t alter the camera pitch I’m not sure what else I could be changing.

The value you pass to that function is ADDED to the pitch. You want to clamp the resulting pitch value.

Your clamp also has Min and Max around the wrong way. If Rate is actually a -1 to 1 value then you will always be adding 20…

Ooh that makes sense, I can’t believe I missed that; thank you! :slight_smile: