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!
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
Since I haven’t found a way to write PM, all that is left is to reply in this topic. Hope it is till active. @pezzott1 i have mostly the same idea which need to be implemented yet i fail to follow your code. The idea is that on certain boolean true get the camera clamp +/- certain angle from forward vector of my character. Yet your code focused more on arrows which my character don’t have. If you have time I would be gratefull if you can help me handle this matter.
Perhaps this might be a bit clearer:
Using a pure function:
I could follow the code, much clearer, thanks. Yet, you have colapsed nodes called “YawLimitDeg / 2” which return some value. Will you be so kind to explain that colapsed nodes too please?
It’s a Math Expression node. Worth checking out.
YawLimitDeg is a float variable that I can call just by typing the name in the expression node and it handles the rest as long as the formula is correct.
create this automatically
You are my hero! Really thank you sooo much. I have no math mentality so it is very confusing to me. You literally saved my diploma project.