Stop first-person camera leaning when against wall?

Hey all. I’m implementing a lean system into my first-person game, so the player can see around corners, and hopefully, lean against doors/walls to hear “hear what’s behind them.” Pressing your ear against a door, basically.
I’ve got the leaning system working, through a timeline. Pretty simple LERP. Problem is, the camera will clip through walls when leaning, as opposed to pressing up against them like I want. Any suggestions for how I fix this? I tried a pretty convoluted “check collision” method where I had a collision box parented to the camera component but that ended up being finnicky. Any easier ways to go about this?

(Some pictures/videos of my setup below. Thanks so much for any help!!!)


Brief video of my setup

Hi @MGRay999, maybe you can set NearClipPlane to a smaller value.
Here is the default value (10cm):


If NearClipPlane is 1:

Your clip plane will always clip on proximity.
You can only get so close before that happens.

Limit your lean based purely on collision results.

Timeline an object with collision and sweep enabled. Stop the timeline when the collision reaches.

Apply the same logic to the camera, or attach the same collision object to the camera so you get readings as the effect is actually occurring.

Then if you notice clipping you can exapnd the size of the collision to prevent it.

This is basically what I ended up having to do ^^^
I created a trigger box and made it a child of the first-person camera in the First-Person Character BP viewport, so the box would move with the camera as the lean happened.
From there I had to do a bunch of checks using several different bools tied into the Timeline that determined when the timeline would stop or reverse upon collision with the environment + player input. Ended up getting way more complicated than I expected, but it’s basically working now. Video of the setup below. Resorted to using Event Tick eventually (which I’ve heard is generally a bad thing? Like you should always find an alternative to Event Tick when you can?), in order to pick up on collisions between the camera trigger-box and walls when the player was already fully leaning. (I think this could’ve been done with Sweep? But idk, haven’t used that before, I’ll probably go in and try to simplify some of the collision stuff using Sweep on the Set Relative Location node)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.