How to handle a collision with a family in an effective way?

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

    I have a problem with a - seemingly - simple problem.

    Let's say a bullet hits an enemy. All enemies are in a family because there are always the usual actions (like destroying the bullet and the enemy etc.)

    But some enemies are different, they have a different behaviour or an effect which has to be disabled while "dying" and so on..

    Let's say there is EnemyFamily1, and Enemy1 has a "Sine" behaviour (and the family has not), Enemy2 another behaviour..

    The condition (on collision with EnemyFamily1) won't allow me to set specific behaviour for Enemy1 (every action regarding Enemy1 will change ALL instances of Enemy1.. and not only

    the instance which was part of the collision...

    What is the solution for this problem without checking for the same collision for every different enemy type? I mean, families are meant to avoid redundant code right? But how to

    achieve this if I cannot "break down" the object types in the collision handling with the family?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use a subevent to "Pick by UID" for each object in the family and perform your actions. Since only one of those can possibly pick anything, only the relevant code will run.

    http://www.blackhornettechnologies.com/Construct2Stuff/FamilyToObjectPicking.capx

    Drag the yellow sprite over each purple and green sprite. Purples turn clockwise, greens turn counter-clockwise.

  • Wow, thank you.. I've seen these "Pick" methods, but couldn't wrap my head around their implementation... Your example is perfect! Thanks!

    Only problem which remains is the order of actions which are to take.. As I said, I've some actions which are only fitting for some of the family members, I can pick them by UID in a subevent now (thanks to you), but the actions for the family itself are already done at this point.. which is unfortunate in my case. Let's say the last action of the family "EnemyFamily1" is "Destroy", then in the subevent the picked "Enemy1" will never see an action.

    There is no way to "get back" to the family after drilling it down to the family member in the subevent via the Pick method, or is it? There's "Pick all" method but I think that means something different.

    And starting another event.. well, as I said, I want the whole collision handling with the bullet in one event, seems the best solution to me...

    EDIT: Okay, MAYBE I've found the solution myself.. I first write all the actions for the family which can be done at the start in die beginning, THEN create a subevent and pick the right family member, perform the actions regardings the family member, THEN create another subevent and Pick the Family via UID again and perform the rest of the actions regarding the family...

    At least that's a solution which worked for me.

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