• News

• Industries

• Learning & Support

• Community

• Marketplace

3rd Person Camera - Best way to automatically have it adjust pitch

Posted this in another thread, but this might be a better place.

So I am trying to make my camera automatically adjust based on the slope of terrain that my player is on. Flat ground will keep the camera where it is, going up a hill will lower the camera a bit, and going down a hill will raise the camera a bit.

I am relatively new to Blueprint and I think I have the logic correct (in my head at least), but I am having trouble making it work correctly in Blueprint.

I am doing all of this in my character controller, and I originally started with the 3rd Person Template, if anyone has any guidance or suggestions I would greatly appreciate it.

Use line traces. one ahead of player one behind.
As result you should get 3 points in d3 space: 2 trace hits and one for feet location of player pawn. Get Z values of both trace hits, and player feet location. Calculate both angles: for trace ahead and behind player.

You will have 4 cases:
player goes uphill, player goes downhill - just calculate slope, for eg difference of both hit Z values to where player feet are.
Player is on top of hill - i think default angle.
Player is in hole - pick forward trace Z value to calculate slope, (fake rear with negative Z of forward one).

So when you have those values, do average of forward angle and rear angle. Multiply that by some parameter. An you will have desired rotation of camera.

Now best way to manage camera imo:
add â€ścamera armâ€ť enable some decent angular lag, keep velocity lag low.
Connect camera to that arm.
Remember arm default rotation as some value.

And because you enabled lag for camera arm, it should move very smooth.

PS. you can also add a bit of such camera rotation (slightly turn it to sides) for situation when player walks along slope (ie. slope is on left - right direction)

Hi Nawrot, after 6 year im not good to translate that in blueprint, can u help me?

If i have time i will do something like that, optimized (learned more tricks with vectors in blueprints).

Thanks U so much, I tried but I have no advanced programming skills

I done project, it is on google drive:

I did not make it with vector math, because of two things:

• would be confusing why and how stuff works
• details on level (like small rocks anything with collision etc.) can screw vector math. So it would need some smothing, or edditional checks calculations

So instead i did it almost like i described 6 years ago, only for left/right, but there are macros that easily can be used for forward/back calculations.

Really thank you I appreciate ur work! ur awesome. now I will work on camera adjustment itself

I did not connect all logic to camera, but you just move camera arm, or tilt it to sside, whatever effect you want.

am I asking too much if I ask you to help me with this step too?

I explain my problems:

• no idea about your levels. That means how much detail you will have on floors and slopes. This is important, because with low level detail all that tracing could be done with just one trace and normal vector to surface. However if its common that such trace would pick up pebble or other small detail, you need more traces to make average out of it. For eg. in standard 3rd person level, sometimes trace picked up tiny â€ścrackâ€ť between meshes and decided player is in valley. So this is first problem.

• more traces means more â€śwastedâ€ť resources and cpu power, so this must be minimal, ie. as few as possible.

• i do not know how you want your camera react to different situations. Honestl;y i could not think about any camera reaction to slope et. that would not annoy player and add something to gameplay.

This all needs some thinking, and planning, but that planning needs knowledge about game mechanics etc.

I think i know what you want to do. For eg. camera zooms in and pans down when you walk to the edge, or shows more up slope when you climbing up. Systems for making that should be coded at beginning of development, but tuned and finalized after you have solid gfameplay and levels, and idea about how game works.

So i can add some camera modifications and â€śgenericâ€ť ie. programmer like behavior for camera. Without thinking if that is good or bad for gameplay.

hi, Iâ€™m looking for recreating something like this for my 3d platform game. i want that the camera follow the slopes going to stand up when the player is uphill, while lowering when the player is downhill. I repeat that I am really very grateful to you for the work you have already done, as I would not have been able to do it alone

Done new version for that:

It traces bunch of points around character, then gets average out of it, and calculates dot product (cosinus beetwen vectors). Then that is used to move camera arm. Done only for forward axis, but calculations are ready for left right also.

1 Like

this is an amazing result. just one problem, I want to be able to control the rotation of the camera, just like in mario odyssey

but it controls rotation of camera arm, and because camera is attached to it, it also moves.
Camera arm adds lag and can smooth out movement.
That stuff works like in movie on YT you posted link to.

I will be more clear, i need to use pawn control rotation

You have all math there, so copy logic over to your project with pawn control rotation.
I put all in macros and somewhat commented them, should not be hard.
Pawn rotation control and all that had some niuances to make it working and i forgot how to setup that correctly in unreal.

when i select â€śuse control pawn rotationâ€ť the code dont works, the camera isnâ€™t moving

That is the stuff in â€śuse control pawn rotationâ€ť when you select it it overwrites camera rotation.
But that is part of your game setup, independent from code i made. I know i just unchecked that and made example code work. Just code your own camera behavior. You have it all there.

Ok, I read online some stuff, how can i integrate ur code with the normal pawn control system?

Iâ€™m using this code to auto adjust camera left and right and for get close to player when there are wall around