How do I change a variable of an instance in a family

Get help using Construct 2

Post » Tue Oct 24, 2017 7:34 am

Hello :)

I have the following code:
Image

Currently the behaviour of this code is as follows:
  • All instances start their path finding process
  • When one enemy stops, all other enemies also stop even though their distance to the player is bigger than the minDistance

How can I change it so that only the enemy who is within the radius stops and the others keep moving?

Here's another exmaple

Image

This is what's happening:
  • When one character moves, the "movement" instance variables of all characters are set to "run"
  • When one character stops, the "movement" instance variables of all characters are set to "idle"

What m I doing wrong?
B
9
S
2
Posts: 10
Reputation: 497

Post » Tue Oct 24, 2017 8:59 am

@25games It's essentially the same problem in both examples:

In the first example the issue is with event 3; you don't actually have any enemies picked, so if *any* enemy's distance is less than the min distance then *all* the enemies will stop. You can either use a "for each enemy" condition or swap the condition around to check if enemy.minDistance > distance(Enemies.X,Enemies.Y,Player.X,PlayerY) to ensure each is checked individually.

In the second example the problem is with the Else conditions in event 7 and 8: event 6 will check all Characters for "attacking"; If *any* Character is not attacking then *all* Characters whose velocity > 10 will be set to run, but the "Else" in 8 means that if *any* Character's velocity is less than 10 then *all* Characters will be set to idle.

The trick here is to use inverse conditions: swap the Else in event 7 for "Character is NOT attacking". Make the velocity check and event 8 sub-events of event 7 and swap that second else for character velocity <= 10.

As a general rule, avoid using Else for checking against objects, especially where multiple instances are concerned.
B
23
S
9
G
4
Posts: 500
Reputation: 4,417

Post » Tue Oct 24, 2017 11:21 am

Thank you very much - now I understand how the objects are picked! Thank you very much!
Have a nice day :)
B
9
S
2
Posts: 10
Reputation: 497

Post » Tue Oct 24, 2017 11:35 am

Thanks, you too! :)
B
23
S
9
G
4
Posts: 500
Reputation: 4,417


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 22 guests