How to get Player to Stop at Edge of screen

I have conditions set to make a character move back and forth, similar to this;

How can I make the player stop at the other end of the screen, and be able to move again on press?

1 Like

The most simple way to do it is to use an invisible object at each end of the screen and check collision with this object and also use a variable to set direction of movement.

For example let say we have a scene variable called direction and the default value is 1

At the beginning of the scene : Do = 1 to scene variable direction

And then, move the player in to a direction based on this value. If the value is 1 move it right, if the value is -1 move it to the left.

And then check collision with an object at the end of the screen.
If player is in collision with the invisible object at the end of the screen, Stop it using the event Stop the object and multiply the direction value by -1

Do * -1 to the value of scene variable direction

So then if mouse is clicked and the value is 1 move it right, if -1 move it left and each time the player collide with the object at the end, stop it and change this value.

Something similar to what we do in the Platformer template for the enemy slime to make it move left and right.

2 Likes