How do I make an enemy teleport away from player?

  • For the game I'm currently making, one of my enemies is a ranged unit. For this enemy I want to make it so that whenever the Player gets close to the unit it simply teleport's away within a certain range. However I can't figure it out for the life of me, any help would be appreciated

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well to teleport it would be set position I guess. If distance between the two is such a value then set the enemy's position to self +/- some value. Pretty simple unless you are looking for something more elaborate.

  • I suspected that's how it would go, however I'm still new to Construct 2 and have no idea how to implement that into my game.

  • You could use system compare two variables, if distance(player.x,player.y,enemy.x,enemy.y) less than equal to the 'range value' then enemy set position self.x or self.y +/- value depending on direction. The distance formula calculates the distance between the two objects. You could also do it another way which is to stick an invisible sprite on the enemy and have when player overlaps that sprite then teleport the enemy with set position, the both accomplish the same thing though.

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