Stop Camera when Player is Out of Screen

Hello :slight_smile: I need another help:) I have camera that is moving in X direction but
want to stop it when player is out of screen it is possible ?

I can stop camera if player have collision with enemy etc

So now need some condition that check player is still on screen ? :stuck_out_tongue:

thx a lot for help

If you have an event that makes the camera follow the player, then add conditions to that event that check the position of the player before moving the camera.

Change this:

No conditions | Do =Player.X() to X position of camera (layer:)

Into this:

The X position of Player is >0 | Do =Player.X() to X position of camera (layer:) The X position of Player is <3000 |
This will stop the camera moving if the player moves left past 0, or moves right past 3000.

Just want to chime in here that this was super helpful for me.

I did tweak it a bit. I wanted it to be based off the player’s center (rather than just their X, so they stay in the center) so I used Player.PointX(“Center”).

Also, you’ll want to tweak your numbers based off 1/2 the width of your game resolution.

So in my example, my game is 1280 wide by 720 tall. My event is set up with a condition to only follow the “Center” PointX if both of the following are true:

The X position of Hero_1_Hitbox is >= 640
The X Position of Hero_1_Hitbox is <= 3200 (my total width of my level is 3840)
Do = Hero_1_Hitbox.PointX("Center") to the X position of camera

There is probably a way to do this more dynamically, but I’m not sure how to detect the total width of a level or detect your resolution setting.

Edit: As a heads up, right now “Center” point doesn’t work unless you use “Centre” in your event. “Center” is ignored and treated as invalid/origin point.