How to trigger condition using the distance expres

Get help using Construct 2

Post » Thu Aug 01, 2013 9:31 pm

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.

ThanksDoudouSupreme2013-08-01 21:41:39
B
12
S
2
Posts: 85
Reputation: 899

Post » Thu Aug 01, 2013 9:52 pm

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
B
12
S
4
G
2
Posts: 59
Reputation: 3,799

Post » Thu Aug 01, 2013 11:03 pm

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 :)
B
12
S
2
Posts: 85
Reputation: 899

Post » Fri Aug 02, 2013 3:26 am

So I have tried what you suggested and created a test capx to do it: https://www.dropbox.com/s/nli4zrilinz0n79/Test_NME.capx

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?

B
12
S
2
Posts: 85
Reputation: 899


Return to How do I....?

Who is online

Users browsing this forum: mikehive and 3 guests