Help with making enemy follow player

  • I'm trying to code my enemy to follow the player. This is my current code but after the Enemy.X = the Player.X the enemy starts moving left and right rapidly. I would like it if the enemy has the same X as the player and then starts move up and down after both X's are identical, but anyway to make this work is fine. I also only want the enemy to move in four directions(left, right, up, down) since I'm trying to make a pixel RPG. Thanks!

  • Can someone please help with this? If it's not clear enough on what I want, I can clarify if that is needed. Thank you :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The reason for the enemy's rapid movement is sub-pixel positioning.

    When the enemy hits the player's X coordinate - let's say 500 - it doesn't stop EXACTLY on the 500th pixel and might stop at, say, 500.27546373 or something. This causes it to think that it is to the right of the player, so it will start to move left, at which point it will stop at 499.37383926 for example. Then, it thinks it is to the left of the player... and repeat... :)

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