Limit SpringArm Rotation

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)

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

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?

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

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

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

could it be gimbal lock?

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.

what do you mean?

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

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.

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

See the documentation here.

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.

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 :slight_smile:

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