Family issues

Get help using Construct 2

Post » Tue Mar 26, 2013 8:56 am

I'm trying to use a family for my npcs to simplify certain events, and I'm having trouble figuring out a way to do this line of code:

For each NPCS (family)
- distance(Sprite1 & Sprite2) < 100
- - (action) - - Set Variable to 1

- distance(Sprite1 & Sprite2) > or = 100
- Trigger Once While True
- - (action) - - Set Variable to 0


So if there are multiple NPCS on the screen, it's always calculating that the player is > 100 pixels away from at least one of them, so the variable is always set to 0.

If I switch the family for any sprite, it works fine (for obvious reasons). Is this something you can't do with a family?
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Tue Mar 26, 2013 9:02 am

Shouldn't you check the distance between NPC(family) & Sprite2(player)?
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Tue Mar 26, 2013 9:10 am

Sorry - that's a typo. It is actually distance(Player.X, Player.Y, NPCS.X, NPCS.Y)
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Tue Mar 26, 2013 9:17 am

Should work, your problem is probably elsewhere. Got .capx you can show?

for each NPCS
.. distance(Player.X, Player.Y, NPCS.X, NPCS.Y) < 100
... set variable to 1
.. else
... set variable to 0
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Tue Mar 26, 2013 9:34 am

My capx has gotten a little too large to share, unfortunately. I've searched every event sheet for the variable, and this is really the only place it is affected. If I use the same exact lines of code but switch the NPC family (in the distance event) for a single sprite, it works perfectly fine.
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Tue Mar 26, 2013 2:49 pm

take a look at this simple capx - https://www.dropbox.com/s/mrh0ol7t801ofwt/Distance.capx. if it wouldn't help - show the way how you've done it
B
21
S
4
Posts: 29
Reputation: 1,253

Post » Tue Mar 26, 2013 5:05 pm

Thanks for capx, GT88, but it still had the same issue when you add a global variable.

I've figured another way to do it spawning a sprite on each enemy and setting the variable when the player overlaps it instead of using a distance command. Thanks, guys!
B
22
S
3
Posts: 451
Reputation: 2,135


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], Draconinho, peturfoto and 12 guests