How to lock camera Z-axes?

I am trying Side Scroller game. When player jump, camera also do jump. I don’t want to do that.

I read some answers, and moved camera component between character mesh and spring arm. But its not working for me.

When I set Absolute Position then camera doesn’t follow character.

How to lock camera?

Find somewhere in player code/blueprint vector operations like player_position + offset = camera_position. After that operation you need to get camera world position, set Z to some constant number, and then set camera world position with this vector. That’s all.
There is actually big number of ways to do this. Solution above is simple and pretty fast.
How to:
This is not code, it all can be done in blueprints.
Ouch, this is uses spring arm, didn’t know it.
But anyway I’ve created side scroller and opened character blueprint.

Then in blueprint created Event Tick (called every frame). Notice, that in spring arm properties in the right side there is Traget Offset. If we can see variable - then we can use it!

Then I made variable for camera’s height.


Dragged spring arm to event graph, then dragged node, in search printed “Offset” and chosed “Set Target Offset”.

Doing all the same with other components do something like this:

This is easy scalar (not actually vector) calculations, you’ll figure out :slight_smile:
And viola! Try this out, it works, but i’am out of attachments here.
And yeah, you need to turn off “Do Collision Check” in spring arm settings, or camera will sometimes go into walls.

It sounds really simple. But I don’t have knowledge of Coding. I’m doing all stuffs with Blueprints. And I can’t find something like “player_position + offset = camera_position” in Details of Character. Can you show me how to do this via blueprint.

Updated my answer, now with tutorial :slight_smile:

Thank You Sir. It worked. But I wish there were some very simple methods in “Details”. Where we have to just tick or untick and then Bingo. :smiley:

Thanks Again for detailed tutorial. Marking as answer. :slight_smile:

This worked for me as well, but is there any way to do this so that you could actually get the camera to unlock when you go downwards and lock back up? or would the camera have to transition to a different camera - if lets say you want to climb down a ladder or up to a high place thats above? So that the camera follows you but then stays at that level until you come back down

I’ve just done something similar for a twin-stick shooter game I am working on. I want the spring arm and camera attached to the back of the player actor, however I want the camera to aways points towards positive X (north). I simply turned off “Inherit Yaw” in the Spring Arm properties and that did the trick:


@HungryDoodles Would you mind if I used your blueprint in a game I am making. I would likely be selling the game I would use it in. Please reply.

Of course you can, I don’t even know the reason why you can’t use it :slight_smile:

Thank you so much I plan to use a variation of it in my game. How should we credit you if you wish to be credited or would allow us to?

As like a special thanks or something like that

No need to, it’s simple little blueprint, not a plugin or a module. Just 1 arithmetic operation and 2 vectors, my real code takes about ~150 lines of C++ for a one task. :slight_smile: (Too many happy faces!)
It’s OK, really.
But if you insist, so my nickname HungryDoodles is used everywhere, feel free to credit it.

This works for other axis as well, not just horizontal axis. Just change the break vector component & make vector component to the axis you want affected. I didn’t want my camera to move horizontally while I moved. thanks HungryDoodles really simple and helpfull.

Simply triggers. Create blueprint inherited from trigger or empty blueprint. In second case add some primitive that will check for player pawn. When event OnComponentOverlap (primitive) is triggered you need to cast Other actor to your pawn class (where fixed Z code is) and change it’s CameraHeight variable to what specified in your trigger as another variable (let’s call it Camera Desired Height). You can put any amount of triggers and from inside level editor change their Camera Desired Heights to what needed in different places.
If you want disable Z fix than you need to create boolean variable to use it as switch. You need a Brunch (blueprint node) by this bool where on False Target Offset needs to be zero vector (set to 0,0,0) and on True use Z-fixing. Enabling/disabling is similar to above with triggers.

Thanks so much, HungryDoodles, for this fantastic solution!! :slight_smile: