Do action if within distance (issue)

0 favourites
  • 4 posts
From the Asset Store
11 loops of RPG, chiptune/8-bit music. Suitable for any pixel art game.
  • I have an object that moves towards the player if it gets within a distance of 500 pixels of eachother. However, I have 3 of these objects on the same map.

    Only the one that I last placed on the map will be used to detect the distance. Once I get close to it, all 3 of the objects come towards me. But if I get close to the other 2, nothing happens.

    What can I do to make them all separate? If you know what I mean

  • Pin an invisible to sprite to each one, and have a different event for each one that tells it to move towards player when it touches another one of the objects.

    (eg)

    -Object1range on collision with Object2

    • > Set angle towards player

    -Object2range on collision with Object3

    • > Set angle towards player

    -Object3range on collision with Object1

    • > Set angle towards player
  • Nope, 'for each' is all you need.

    +For each object

    +compare two values: is distance(player.x,player.y,object.x,object.y)

        -> actions

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nope, 'for each' is all you need.

    +For each object

    +compare two values: is distance(player.x,player.y,object.x,object.y)

        -> actions

    This works, thank you very much!

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