How do I constrain the camera to the z axis?

I’m making a 2D side-scroller and I’m trying to constrain the camera so it can’t go past min:500cm and :1000cm on the z axis whilst still being able to freely follow the player in between those boundaries, its on a spring arm attached to the player sprite. Every way I’ve tried ends up with a slight flicker on screen.

Any help is appreciated.

Hi

How are you stopping it move?

This is my current way of doing it, but any sprite on the same plane flickers each I turn my character

Just editing and solving all my old posts in case anyone else needs help on this after having years more experience now.

Firstly we need to make a separate actor for the camera, this will be a child of the Camera Actor:
Tut04

Now inside the FollowCamera_BP we need to make sure the camera is set as the main game camera using the Set View Target With Blend node.
After this we then need to create an event and a timer for this event, I have named mine “Follow Player” and set Looping to True and Time to 0.001.

Now for the Follow Player event we need to create a function called “Add Camera Lag” (This is optional only if you want camera lag) and we will return to this node later:

This Follow Player event is simply setting the FollowCamera_BP’s location to the Player Character’s location with optional camera lag.

You will see I have created a Vector2D variable for the X and Z axis. These values will determine in the world how far the camera will be able to travel in those axes. I have set the minimum defaults for both of these values to 0 meaning the FollowCamera_BP will never be able to move down past 0 and never scroll left past 0. The player, however will still be able to move freely so be sure to block the player as to make them not go off screen.

Now for that Add Camera Lag function:

This function is very simple and is a lerp node with its Alpha pin being multiplied by the Get World Delta Seconds node by a Lag Amount pin in our functions inputs.
(Lag amount set to 0 results in disabling the lag completely)

Hopefully this helps those 2D game devs stuck like I was 9 years ago!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.