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!
This is easy scalar (not actually vector) calculations, you’ll figure out
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.
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:
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. (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.