camera offset/shift when near wall

Hi,

I have a third person camera that I want to automatically reposition if the player is very close to a wall. I have created my own PlayerCameraManager and added a CameraModiifer with the BlueprintModifyCamera.

I hope this makes sense but essentailly when close to a wall that ends on the left the camera should move to allow the player to see better. The right doesn’t matter too much as by default the camera sits on the right

Hey @DarkEmbrace96!

Are you asking for help with this? There isn’t really a question here :stuck_out_tongue:

You could have two locations for the camera and use “Set Relative Location” to set the camera to point A or point B in relation to its direct parent in the hierarchy! For detecting a wall on the left or right you should use line traces on tick to detect a hit vs static object. :slight_smile:

Hi,
Yes sorry, forgot to post the actual question but you’re pretty spot on.

With the line trace or say a sphere trace is there a way to detect what side of the sphere is blocking a hit I.e if 60% of the right sphere is hitting something then shift camera left.

Alternatively is there some calculation the camera does it self that could potentially replace a trace??

So you can have line traces go in any direction you’d like, or place a small sphere trace on each side of the player in locations you prefer. I like to make scene nodes for them to attach to on the front-left and front-right for corner leaning. Many who haven’t used them think of them as hamster balls, but they can be placed anywhere- they’re more like a “Point trace” that can be expanded.

As far as I know, you can’t get % of coverage in a single sphere trace.

There is not some other calculation the camera can do- anytime you see functionality of camera-based automatic shifting it’s almost certainly the result of a trace, then a reaction in the code based on results of the trace.

A trace is typically the cheapest method of retrieving dynamic information about the environment, you will want to become familiar with them! I suggest using this low-impact game mechanic as an exercise to get well-acquainted with them! :slight_smile:

1 Like

Thanks for the detailed response, that all makes sense

Don’t suppose you have any tips on how to combat this camera glitching?

I think it’s totally doable! It’s plain that the camera dancing is due to the way the camera code is set up- you’ve made a really good first leap! You just need to add some edge case solutions! Here I’m thinking add a timer that disables the line trace for a few seconds- long enough for the camera to reorient where it needs to be! But it all depends on how your code is set up, there might not be a need for a timer if you use a timeline and LERP to move the camera. :slight_smile:

1 Like