Getting an enemy to walk back and fourth

So I’ve followed one of the YouTube tutorials on how to do this and I thought I followed it perfectly, but my enemy just collided with the arrow I’ve placed, flips, but doesn’t start moving the opposite direction. Here’s my code

Ps I’m BRAND new at this. I’ve never attempted anything like this before. I’m helping my 10 yr old son figure this out to create his own game based on the characters from his own comics, but we’re both stumped here. Please assume I know literally nothing when responding lol

Hi,
the last block in your events has to be deleted. Because of that your enemy will always march to the left.

So, this right? That makes sense, but without it the enemy never starts moving. So where’s the best place to add this? I tried at the top but that didn’t work

I see. The action has to go into the block with the “At the beginning of the scene”- condition. The enemy will start to move and if it collides with the arrow the object variable “direction” will determine the next move.

Thank you for your help so far! Still not working tho. See anything wrong here?

Nothing wrong there that I can see. Perhaps something else in the game is causing issues…

Also, since you already have events that cause the enemy to move left and right when the direction variable is set, you can just set a default value for ‘direction’ in either the enemy object itself, or in the ‘At the beginning of the scene’ event.

You are telling it that when it hits the arrow facing right to go left. And when it hits the arrow facing left to go right. This is inverted from how all of the tutorials are written that I’ve seen.

The arrows should act as bumpers, so when you are walking left your enemy will bump into the arrow pointing right which turns it around and walks away to the right.

Additionally, none of your events are setting the initial variable value, so ensure your enemy has a Direction variable precreated on the obiect, and it is set to “Left” or “Right” (everything is case sensitive so “left” or 'right" will not work.)

Blockquote Additionally, none of your events are setting the initial variable value, so ensure your enemy has a Direction variable precreated on the obiect, and it is set to “Left” or “Right” (everything is case sensitive so “left” or 'right" will not work.)

Blockquote

Could you show me specifically what this would look like? Not sure how to set an initial variable value

I think that’s what I did here, but no luck

Sure thing. Two ways to do this:

  1. Add a “Change the text variable direction of Enemy1 = “Left”” action to the “At the beginning of the scene” event.
    or
  2. In the scene editor, double-click your Enemy1 object from the object list. Click on the “Variables” tab. Click to Add a New Variable, name it “direction”, set it to the “String” type, then populate it with “Left”.
1 Like

THANK YOU SO MUCH!!

You’re right we did have the left and right switched after many times deleting all of our conditions and starting a over.
Changing the variable in the enemy Sprite worked perfectly. Sigh!

1 Like