Enemy Movement

How would you make an enemy move left to right and go the opposite direction when hitting a wall, like a goomba from Super Mario?

2 Likes

Good question! There are a couple ways to do this.

The simplest method is to use the “bounce on wall” flag for sprites:

However, this isn’t true “goomba” behavior because it won’t work for sprites that have gravity. In mario, goombas fall down when they walk off a ledge. To copy that behavior, we can use an “on hit wall” event instead:

There are comments in both those example that explain the code!

2 Likes

Thank you, this helped a lot :slight_smile: