• 2D
  • Bouncing enemy

Hi :) Im trying to port my old (and unfinished ) game to Godot. It's a platformer. One of the enemies is bouncing from left to right. Well... thats what I want. For now when this enemy hits a wall it's bouncing in place with no direction change. How can I detect when enemi hits the wall to change directions? I use tileset (staticbody2d) for my level and kinematicbody2d for my enemy. THanks in advance :)

Welcome to the forums @BadSadCoder!

What does the code for your enemy look like? Most times, a bounce or change in direction is generally just flipping the a positive value to a negative. For example:

if (is_moving_left == true):
	velocity.x = -MOVE_SPEED * delta
else:
	velocity.x = MOVE_SPEED * delta

And then you would just need to change is_moving_left to true/false when the character collides off the wall. That is just one way to handle it though! There are other ways that might work better depending on your project.

To add onto what @TwistedTwigleg is saying, you can know when the enemy collided into a wall withis_on_wall().