Screen Boundaries

I am very new to using gdevelop and I have followed the Tank Shooter tutorial. I added top down movement to the player and added WASD keys, however I have found that the player can continue moving past the original screen size. My question is:

How do I create some sort of boundary that the player/enemies cannot move past (such as the ‘invisible walls’ from many older games)?

You can, set a limit to the X / Y value; if the player/enemy is close to that value it will always be equal to that value. (So it won’t go past that value).

Where do I set up this X/Y value?

If you are dealing with a world that is a big rectangle, then checking the X and Y positions will work.

Just use a condition that checks the position of the player object using

all objects>Position>compare X position of an object
or
all objects>Position>compare Y position of an object

If the limit to the left is 0 then check if the x position of player<0 as your condition. For the action you just stop the player (all objects>movement>stop the object) and set their X position to 0 (all objects>position>X position of object).

If your world is not a simple rectangle in shape then checking X and Y values becomes more complicated, so you might be better off creating an object to use as an invisible barrier.

Create a new object and call it barrier. Then give it a really small square sprite e.g. 8x8 pixels. Drag it onto the scene and then resize the sprite vertically to make a tall, thin rectangle side barrier or horizontally to make a short, wide top/bottom barrier. Ctrl-drag to make as many copies as you need of these long rectangles to completely surround your game world. You then need to do two more things:

  1. In a new event do a collision check between player and barrier as the condition (from all objects>collision) and choose “separate two objects” (from all objects>position) as the action.
  2. In the “at the beginning of the scene” event, hide the barrier object (from all objects>visibility).

could I have a sample code for this? I’m new to this and am in great need of it, thank you!

Alternatively you could just make an object that that player can’t pass through (Make it invisible if you want) by using the separate 2 objects action. I can provide sample code if you need it. Or use the platform behavior for the boundary and platformer character behavior for the tank (Disable gravity and default keybinds on the player) so that way the player won’t be able to pass through it (This is good if you don’t want to write extra code)