How do I make enemy sprite go towards my player?

  • I'm attempting to make a side-scrolling platformer shooter thing, but i can't get the simplest thing to work.

    I have multiple of the same enemies, which i need to go towards the player. I want to do this by making the enemy sprite see if it is to the right of the player (Has a higher X value,) and if so, the enemy will move left (using the platform behaviour with controls disabled), and vice versa. This works well for only 1 enemy.

    But for 2/more enemies, they all move in one direction based on what one of the enemies' location is compared to the player. I tried using instance variables for each enemy to see where it is compared to the player, but for the action of that event, all the sprites moved in the same direction.

    I thought this is because i'm using the platforming behaviour but it didn't work when i used moved forwards either. I don't know how to get each enemy to move in the direction that will lead them to the player. Sorry for explaining it awfully.

    Here is how it looks when using platform and move forward.

    (The blue square is the enemy, Direction is the instance variable, the value of Direction is which direction it needs to go)

    Thanks for any help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Your picking is a little off, you should pick the enemy in both the condition and action. So you say if enemy.x > player.x set enemy direction left etc.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)