Locking and Unlocking Camera

I marked as C++ Programming cause I am trying to use C++ as much as possible as a way of getting a better knowledge and feel of the language.

Okay, first things first, I’m gonna explain what I want. I am making a platformer game, much like the Megaman X series. In those games the camera follows the player around, almost every time making the player character stay around the middle of the screen, however, when you reach, say, the ground or the corners of a room, the camera stops following you and remains static, as to not go out of bounds.

Now for my question: how can it be achievable?

Hey there, i would probably do something like this: I would maybe define a box component that would serve as the bounds for the camera’s position (so that you don’t have to hardcode values). Then on the camera’s actor tick i would be clamping it to be inside the bounds.

Yeah it could be with a box collision. I’m probably talking about the player’s tick event, the camera is attached to the player right?

The box collider is not supposed to collide with camera, it’s just a way to define in 3d space the place where the camera can move, you have to defined that in the tick. I know the camera is attached to a spring arm, but is that on the players blueprint?

I’m not sure I follow. You’re suggesting to use Box Collision, right? But I have no idea what you mean by camera’s tick.

The camera is attached to a Spring Arm. It’s the default from the Sidescroller template. I tried using the box collider, but the camera still clamps inside the invisible wall I’ve put there for it to collide, trying some different stuff now

If you dont want to use the box collision you can manually define the Min and Max Limit in world coordinates, so you just make sure that your camera is always inside those values.

Yes but you did not understand the box collision idea, the idea is just to have a volume that surrounds to world, it’s not supposed to have any collisions, it’s just serving as a volume.

Also, isn’t the box collider supposed to be used like this?

It’s not that I don’t want to use box collision, it’s just not working at all

And how would the camera understand that it’s not supposed to go beyond this volume?

Every tick you would be forcing the side axis (does the camera move horizontally in the Y axis?) of the camera to be within the box world position ± the extent.

It moves only up-down-left-right. Gonna try this

I’m using this “Camera Blocking Volume”. It’s blocking the Z Axis just the way I want, but the Y axis doesn’t seem to be locking, any ideas as to why?

Well, it is blocking the Z translation.

It still works with the box, you need to clamp the Y and the Z.

Afaik that only blocks the rotation and not translation.

It’s the translation that comes from the rotation of the camera by using the spring arm. Is it possible to send a gameplay picture so i can visualize better what you are trying to do?

Yeah that’s what i thought, the camera blocking volume will block the camera but for horizontal movement it wont work very well. I tried implementing my approach, but with hardcoded values like:

And it works perfectly:

Sure thing, let me just open the editor here real quickly