Distance, multiple instances

Get help using Construct 2

Post » Sat Dec 29, 2012 11:22 am

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
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Sat Dec 29, 2012 11:50 am

It's a matter of using the pick nearest instance condition.

capx
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Sat Dec 29, 2012 12:01 pm

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.
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Sat Dec 29, 2012 1:17 pm

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.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Sun Dec 30, 2012 12:02 pm

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.
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Thu Sep 12, 2013 9:10 pm

@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.eli0s2013-09-12 22:08:42
composer - multimedia artist
www.eli0s.com/en/
B
53
S
21
G
3
Posts: 1,125
Reputation: 8,091

Post » Thu Sep 12, 2013 9:36 pm

Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Sep 12, 2013 10:29 pm

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!    

That was a mean .capx my friend, thank you so much!!!

Elias
composer - multimedia artist
www.eli0s.com/en/
B
53
S
21
G
3
Posts: 1,125
Reputation: 8,091

Post » Thu Sep 12, 2013 10:38 pm

[QUOTE=eli0s]That was a mean .capx my friend, thank you so much!!! [/QUOTE] You're welcome!
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests