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

0 favourites
  • 4 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello

    I have the following code:

    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

    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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thank you very much - now I understand how the objects are picked! Thank you very much!

    Have a nice day

  • Thanks, you too!

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