How to trigger condition using the distance expres

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi guys,

    I'm trying to the following thing:

    If enemy "is alerted", pick all enemies that are "not alerted" within say 200px distance of that enemy and change their variable to "is alerted".

    How would you do that? I'm struggling to do that in Construct2, any help would be greatly appreciated.

    I don't want to have NMEs doing nothing when one of them has for example spotted the player, that's why I'm trying do to that.


  • Off the top of my head you could try this? This might work if only one Enemy can be alerted at a time. Otherwise, you'd need to Pick nth instance to limit it to one.

    (Create a couple variables X and Y.)

    Variable X

    Variable Y

    (When an enemy is alerted, record it's position)

    [event] if Enemy becomes Alerted:

    [action]X = Enemy.Position.X

    [action]Y = Enemy.Position.Y

    (then compare all the enemies to that position)

    [sub event] Pick All Enemies

        [sub event] System | Pick by evaluate distance(Enemy.Position.X, Enemy.Position.Y, X, Y) < 200

        [action] Enemy become Alerted

  • Thanks I'll try this, did not think of recording the position in a variable to use as trigger. Will let you know if that works for me :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So I have tried what you suggested and created a test capx to do it:

    I used local / global variables. I was wondering if there was a simple way to do the same thing without using local / global variables but instead the variables of the NME family for instance?

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