How do I Pick Family Instances Consistently Within Events?

0 favourites
  • 3 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I'm working on a fighting game, and rather than duplicate the code for Fighter1/Fist1/HealthBar1 to have 2 (or more) fighters, I'm trying to leverage families, with objects being picked based on them having the same PlayerNumber instance variable.

    I have this mostly working, but there are 2 particular situations where I'm running into a lot of issues.

    Here is where I'm trying to put the Fists and HealthBars at the right spot for each fighter, as well as resize the HealthBar appropriately. The stuff referencing Fist1/Fist2/Fighter1/Fighter2/Health1/Health2 is what I currently have working.

    The stuff below just referencing Families does not work correctly (both Fists and HealthBars are stuck on Fighter1, while Fighter2 has nothing). It looks like the issue is that the Event is not correctly picking a Fighter instance, and so the Action just refers to the first Fighter it finds.

    Here is where I'm detecting active attacks, and calling Damage appropriately. The top stuff referencing Fist1/Fist2/Fighter1/Fighter2 is what I currently have working.

    The stuff below just referencing Families does not work correctly (whenever either Fighter attacks, the other takes damage regardless of proximity to the former's fist). I think this is a similar problem to what I explained above, where the action is not using the same fighter that's referenced in the event (basically, Fist1 is always overlapping Fighter1, and then a different Fighter is found with a PlayerNumber separate from the Fist, and so that Fighter gets Damaged).

    I have workarounds, and there are other things I could do differently, so I'm not trying to solve the problem so much as understand what's causing it. It's frustrating because Construct 2 is normally so automagical with Instance Picking, but that functionality seems to completely fall apart when dealing with families.

    Any clue what I'm missing here?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When creating events it's always necessary to reference the object you want the actions to refer to..

    your first event would work if you picked the right fist for the right fighter..

    Right now no fighters are referenced in the event..

    So you probably mean for the first event:

    system for each fighter

    system pick fist by comparison fist.playernumber = fighter.playernumber

    fist set position to fighter

  • Ah, I was thinking that using the Fighter in the Fist's "Compare Instance Variable" value slot would end up picking that same fighter, but I see now that's not the case. Using "Pick By Comparison" instead works perfectly. Thanks!

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