Clamp Camera Based On Character Rotation

Hi, I’m trying to clamp the player’s camera depending on the direction they’re facing, but it’s only clamping towards X in world rotation and ignoring the character rotation, how do I fix this? Here’s my Clamp Camera function (Input values when beam balancing are False, 90, 90, 50)

Here’s a video of what it’s doing Camera Clamp Bug - YouTube

From what I can see you have the camera clamped when player steps on the rail.

You could check the character’s forward vector as the event triggers and set the yaw limit accordingly.

I’m not sure how I would calculate a min and max between -180 and 180 for each axis converted from local rotation to world rotation.

Also if I were to have for example a curved beam the character’s rotation is corrected automatically when walking along it, meaning it would need to calculate the world space values and set them every frame, whereas I’d rather clamp the camera rotation in the character’s relative space once, so a -45 to 45 yaw clamp means I can only look in a 90 degree cone with the center point straight forward from the character, no matter what direction the character is facing

Like this: ThirdPersonPractice Unreal Editor 2021 09 18 20 48 53 - YouTube

Added arrow for visual reference. What I did was inverted character’s forward vector and subtracted/added each arrow with the angle I wish my camera to be active. Right checks if camera’s yaw is < than arrow position whie left checks the same but >.

As long as one is true, I know camera is withing range behind character, if both are false, then camera is out of range. You can tell on what side the camera is by comparing and selecting shortest angle.

Each arrow knows if camera moves behind it and the allowed camera range is set to a single variable. From here it’s easy to add logic that limits Turn event from exceeding the arows.

This updates on character movement, no tick events.

I’ll try and comment what I did… it’s not that organized lol



This is everything.

Hope it helps… this was way more fun than I expected it to be! :rofl:

Sorry to revive this, just wanted to point out is there is a better way to do this: just get the dot product of you character and camera, and you’ll get the camera 180 based on character forward vector. You can also clamp the camera rotation on another actors forward vector with this. Better than doing double the math I did above. Everything else is still valid.

Ah awesome, thank you so much! I kinda got distracted by another feature for a while and forgot about this until now, I’ll give that a go again