When the camera collides with low ceilings it compresses the distance to the player (zooms in), which causes some jarring camera motion in tight spaces, especially when jumping. I tried messing with lag but it’s only a half-solution.
I feel like I just need to limit the camera world height to just below the ceiling so it doesn’t collide and shoot forward. My instinct is to use a line trace up from the camera to detect when it gets close and then “freeze” the z axis. When I try it I get clipping, weird positioning, etc. And I still have to figure out how to “unfreeze” it properly. This is what I have so far. Am I chasing a feasible solution or is there a better way?
I’ve been testing different ways to do this and I think I found something that works great!
You will clamp the pitch angle of the camera only while under the seiling as you think, but calmping it in you “look” input instead of moving the camera every tick.
To do it, you will need to create 4 variables:
Default Arm Length (float): 0.0
Ceiling Buffer (float): 10.0
Max Pitch (float): 0.0
Max Pitch Offset (float): 10.0
And then be sure your character’s camera boon (spring arm component) has the following settings:
And that’s it! You will be able to modify the max pitch using the “Max Pitch Offset” variable. Iff you increase this variable’s value too much, your camera will pass throug the ceiling, so be carefull!
This is how it looks:
Hope this works as you wanted! Let me know if you need more help!
That’s pretty cool, but constantly tracing for ceiling on tick might be a bit heavy. Could probably stick some triggers under low ceilings that send an interface message to player on begin overlap telling them the ceiling height ( could calculate that in editor by getting box extents of trigger in cons script and doing the math there) so the player’s interface function only has to set max pitch and spring length once. If end overlap sends a null value via interface message, have the interface function apply default values.
Wow thanks for taking the time! I like how you’re manipulating the boom instead of the camera position which removes some problems I was having. It works great except a couple things.
When jumping the camera clips through the ceiling. Instead of limiting the pitch would it need to set the pitch?
When the ceiling above the character is higher than above the camera it also clips through because it’s doing the trace from the character.
I think I see what you’re doing so I’m trying to modify it… against the mercy pleas from my programming baby brain.
To keep camera from hitting ceiling, you could brute force it and do a line trace straight down from actor loc in tick then set your spring arm loc to the hit loc+ some offset to match where it is naturally. Might look weird if you jump off a tall building tho. But you could fall back to trace end if there’s no hit. It looks a little odd ( like there’s an actual third person following you with a camera), but keeps camera out of rafters and such..
Could also experiment with camera lag settings so spring root doesn’t follow perfectly.