Distance, multiple instances

  • How would I use the distance() command when applying to multiple instances of the same object.

    I have some simple sprites where if the player gets close to one of them the one it is closest to will attack the player.

    At the moment if the player gets close to one of them they all attack the player. Or if I use "for each" only one sprite at a time will attack the player if the player is close to a group of them, they should all attack.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's a matter of using the pick nearest instance condition.

    capx

  • That is awesome cheers, but this picks only one instance, where if the target sprite is within a distance of say 500 I want the AI to attack no matter how many AI are within that distance.

    Any AI outside of the distance should not be affected.

  • For Each. should be the one you want

    For Each AI

    -sub condition: compare two values(distance(a,b) < range)

    --> attack

    If only one sprite is attacking at a time. Then something else is happening in regards to the each validate check.

  • For Each still only impacts one instance, I can't really work out why. Here's another example:

    For Each "Door"

    - System, distance("door.x","door.y","player.x","player.y") < 40

                - door open

    - System, distance("door.x","door.y","player.x","player.y") > 40

                - door close

    This just doesn't work when there are multiple 'doors' in the level.

  • CrudeMik

    I know that there has being a long time since this post, but have you managed to figure this out? I am having the same problem with you, I want to trigger an action (enable collisions) on instances of the same sprite based on the distance of the player.

    I've tried any combination of "for each" but nothing works with the distance expression. If I use a comparison based on X position values it works, but this isn't what I want.

  • Oh my god tulamide!

    I was under the impression that the x and y in the distance(x1,y1,x2,y2)expression where placeholder names for the objects (Player.X, Sprite.X, Player.Y, Sprite.Y) and the 1 and 2 where representing the x and y coordinates...!!! Now that I think of it, I don't understand how I convinced my self of that! <img src="smileys/smiley9.gif" border="0" align="middle" />   

    That was a mean .capx my friend, thank you so much!!! <img src="smileys/smiley2.gif" border="0" align="middle" />

    Elias

  • That was a mean .capx my friend, thank you so much!!! <img src="smileys/smiley2.gif" border="0" align="middle" /> <img src="smileys/smiley2.gif" border="0" align="middle" /> You're welcome!

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