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)
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
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
1.
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.
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.
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?
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.