How do I...

This forum is currently in read-only mode.
  • I want to have an object that will function as an enemy. When the players object comes within an x number of pixel radius, the object will chase the player. When the player escapes that radius, the object will cease following until the player reenters.

    So basically, an enemy has a personal space, and when you invade that personal space, it chases you until you manage to leave it.

    How exactly do I do this?

    Thanks in advance.

    -Sil

  • You could use system compare with the distance() expression

    System compare distance( enemy.x, enemy.y, player.x, player.y) < x amount

    enemy move at angle towards player, or what ever movement your using.

  • As newt said, you need to compare the distance of the objects. Don't forget to run that compare under For Each Enemy. So basically:

    For each Enemy

    -> Distance(enemy.X,enemy.Y,player.X,player.Y) < attackdistance

    == ATTACK!

  • Thanks, worked like a charm.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another (and faster) way is to instead of using the for loop and the system compare, is to use the compare condition in the enemy object. This is just like the system compare, except the comparison is evaluated for each instance of enemy, picking the ones that meet the equation. So then you would use:

    -> Distance(.X,.Y,player.X,player.Y) < attackdistance

    == ATTACK!

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