How to Make Character Move Left to Right when Touching Wall

Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.

I am attempting to create a game similar to the mobile game, Don’t Touch the Spikes. At the start of my game, I want the player to be able to jump when clicking the mouse while moving from left to right continuously. When the player touches a wall, I want the player character to simulate moving towards the opposite direction.

The player should move the other direction when the player character touches a wall.

Currently, the player character is able to jump up and down and in one place. I attempted to add a simulate key press event to the character, but the character continues to move in that direction even when it touches a wall.

This is what my events look like, if there is any way for me solve this issue, let me know. I’d greatly appreciate it!

I guess you need to assign a variable to your bird. If =0 it moves to right, if =1 it moves to left, and toggle it each time it collides against wall.
Your event makes the bird move only when it’s colliding the wall.

@zutty It worked until I added a platform behavior to the object. Before then, the character could easily pass through the object when the mouse button wasn’t being pressed. Now the player can’t phase through the wall but the player only rotates when its touching the top of the wall rather than the sides.

This is what my events screen looks like at the moment. I tried to do something with finding if the player’s x coordinate is less or greater than the wall(Boundary) and allowed it to change direction but it still isnt working at the moment.

image
You need to add “trigger once” here

Thanks for replying. I was able to find out a way to make it work!

1 Like

@zutty I was able to get it to work properly but now I would like to disable the bird from moving at the start until the player character clicks the left mouse button. This is what I have so far, but I’m not exactly sure whats wrong with it. I added a number variable to the player (ChiChiTheBird) called Direction and set the player to move left if the number was 0 and right if the number is 1. At the start of the scene, I set the Direction variable to 2 to prevent the player from moving until the mouse was clicked. However, when I run the game, It works fine except it will not move left after touching the right wall. Are you able to see anything wrong with my code?

I believe it has something to do with the left mouse is released part. I think it’s detecting that input all the time instead of only once. I tried adding a variable to toggle the event but it still didn’t work. I’m not sure how to fix that.

Why are using “The boolean variable of scene variable leftClick is true” in your 1st condition?
Delete it and I think it’ll work.
A boolean variable will always be false when created, unless you modifiy it or toggle it.


I don’t know what behavior you applied to your Bird, but Activate and Deactivate it whatever it is. (Platformer or TopDown)

Its all good. I was able to figure out a way to make it work. I appreciate your help.