Download

clamping camera?

I am making a 2d infinite runner game, and was wondering whats the best way to prevent camera from going outside my background

I essentially want to clamp it, so it doesn’t ever show below a Y value.

For simplicity, I am just using a basic Character Controller, that has a CameraBoom(Spring arm) which has a child Camera component

I was thinking of just doing a

onTick, clamp y value of boom to be yMin

I was wondering if there was a non ‘onTick’ approach for this?, that just simply prevented it from going too far down, e.g. never go negative y value, or go above y value.
Specifically so that if you are near the bounds, the player will physically appear closer to the edge, but rest of time they will be centered. (think Mario)

Thanks

There are two ways to do this.

  1. With a camera blocking volume.
  2. On the tick method, Get Actor Location -> Break Vector -> Get Y-> If Y Less Than -> Don’t Move Down.

the camera blocking volume, just hides my character sprite when I hit it with my camera.

Is there a special nested hierarchy things must be in for it to work?

Right now I have a character class, that has a child spring arm, that has a child camera. When I collide with the camera blocking volume, makes my character invisible, as well as many other things.

Ah, I actually don’t use the spring arm component. I program the camera independently. I am not sure if this is the Unreal approved way or not.

in every other game framework I’ve used, I’ve always programmed the camera independently. I just saw the spring arm approach used in several video tutorials and other unreal places. So I am not sure what the official recommended approach for that. I’d imagine doing it yourself, gives you the most flexibility and potential advanced functionality. I just didn’t want to reinvent the wheel.

I ended up going with a permutation on #2 though.