Recognizing individuals in Families

0 favourites
  • 11 posts
  • Greetings, Forum. My first post here. I'll explain my problem as clearly as possible:

    I have a Family for enemies in my game, so the collision with the main player can be coded so much easily. My question is: is there any way for the program to recognize which individual in the Family collided?

    For instance, say I have the family "Bullets" with three individuals: Normal Bullet, Fire Bullet and Ice Bullet. I want a different death animation when hit by a specific bullet.

    So, can Construct 2 recognize individuals? Like, "If collision with (Bullet.Family) then (Which.Individual) then (Act.Accordingly)"

    I hope the explanation made sense... Thanks in advance!

    (Max)

  • Yes, C2 will automatically pick the only specific objects involved in the collision

  • Have you read How events Work? Actions only apply to the objects that met the event, so this is not normally a problem.

  • Thank you for the answers. Yes, I know Construct 2 pick the specific objects involved in a condition (fur instance, if a thousand bullets are on screen, only the one that actually hits the target is recognized in a OnCollision event) and yes, I've read How Event Works, but my question is a bit more specific.

    I'll just explain it with a screencap of my game. Here, take a look: CLICK HERE TO SEE THE SCREENCAP

    What you see there is the basic setting for my game. The goal is to outrun and survive an angry mob chasing our main characters. In the screen you can see two of the main hazzards of the game: boulders on the floor and proyectile stones flying from the mob.

    Both the boulders and the stones are inside the same "Hazzards" Family, so I can save code when it comes to hit detection. So far, so good; the game does recognize the elements in the Family as a whole and my characters do get properly hit when in contact of any of them.

    Here's the thing I want to do: when a flying stone hits a character, it should smash into bits.

    So, is there any way for Construct 2 to recognize a specific member of a Family? It would go like this:

    1) Is Family.Hazzard colliding with Player?

    If so...

    2) Is colliding Family.Hazzard object FlyingStone?

    If so...

    3) Destroy FlyingStone and create FlyingStoneDebris on its last shown position.

    Then...

    4) Player gets hurt (lowers energy).

    The part in BOLD is the one I am asking about. I have worked around it by asking, after a collision with the family is made, if there is a FlyingStone colliding, in which case it gets efficiently shattered on command, but it would be nice if we could just have a command that returns the name of the Family member in question.

    For instance:

    IF Family.Member is (object) THEN ...

    I think I'm over-complicating my explanations... Sorry for that, guys. :-/

    (Max)

  • Did you try the condition "On destroyed"? And then an action that creates the debris on this position.

    For instance, On flyingstone destroyed -> create object stonedebris on flyingstone x and y.

    That way it will work every time that object is destroyed on other events.

    Also, on destroyed is a trigger condition so it has to be the first condition.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • put the ice and fire into their own families, when you first fire the bullet say if bullet belongs to family, set damage type to 1: fire etc etc the dmg type being a variable

    so whilst the bullets are all in the same family the ice is its own family too for the purposes of checking if its ice

    I personally put all of my bullets on one object, then depending on bullet type go to different animation, and change dmg stats on shoot

    I find it much easier than making different objects for each bullet type

    ( this is without using the jjweapon plugin)

  • you can always do the following:

    Have the same name for the colliding animation (like "collide") for all your hazard objects and then just call this animation. You then don't need to know which is which.

    However, if you need to create some special effect depending on the family member you collide with, you can always do:

    Add an instance variable to the family called 'fx'

    Then for each of your family member you can set a number for this variable like 0 for no fx, 1 for stone debris, 2 for anything else

    And then

    +Player: collides with Hazzard
      -> Hazzard: set animation to "collide"
      + Hazzard.fx = 1
        -> hazzard: spawn stoneDebris
      + Hazzard.fx = 2
        -> do something else
  • You can take advantage of the fact that each object has a unique UID.

    +--------------------------------------------------------+
    |Player | On collision with BulletFamily                 |
    +--------------------------------------------------------+
    |  +-----------------------------------------------------+
    +--|SG_slug    | Pick instance with UID BulletFamily.UID | Player| destroy
    |  +-----------------------------------------------------+
    |  +-----------------------------------------------------+
    +--|AK47_round | Pick instance with UID BulletFamily.UID | Player| change animation to "painfull death"
    |  +-----------------------------------------------------+
    |  +-----------------------------------------------------+
    +--|bb         | Pick instance with UID BulletFamily.UID | Player| laugh
       +-----------------------------------------------------+
  • I personally use a family instance variable to specify the type within a family just like Yann mentioned and that works fine.

  • Did you try the condition "On destroyed"? And then an action that creates the debris on this position.

    For instance, On flyingstone destroyed -> create object stonedebris on flyingstone x and y.

    That way it will work every time that object is destroyed on other events.

    Also, on destroyed is a trigger condition so it has to be the first condition.

    Ah, I haven't thought of the On Destroyed condition! Thanks, that worked way better than my method! :-)

    Thank you, everyone else! You've given me many nice ideas and good advice. :-)

    (Max)

  • Sorry, but this isn't actually a reply, but a relate question concerning the main topic. I've created a family of individual sprite objects. It looks pieces.X and pieces.Y ("pieces" is my family of sprites) would pertain to each individual sprite in the Family, so I could set an event for a sprite at X and Y equaling some other X and Y using a "For each" loop. My problem is, though it might catch that "pieces" member, it doesn't expose the an instance variable I've set in each of the sprites in the family, which total messes up my idea of why a "For each" would be useful... looping to find an object, then querying it for information. Yes it kind of seems to do that, but not to the degree that I need.

    Its aggravating that I currently have to explicitly test each position of every "piece", in order to retrieve and use its instance variable to perform other actions. I need a way to loop through a set of objects, which I know I've set that instance variable on, find the one I want, and set the value of that instance variable into an array.... "You can't do that Dave." Anybody have an idea... is there an alternative plugin that will allow this kind of individual object access in a "for each" type of loop? BTW, each object (sprite) is similar, but unique in appearance. The same instance variable is defined on each of these, with the value I need. I guess what I'm trying to stress is, the sprites are not simply clones of some single sprite instance (if I'm describing that properly). Thanks!

    [UPDATE] I solved my problem. I first shortened my list of positional checks by doing a "Pick by expression", which allowed me to grab the object I wanted out of my "pieces" Family, at X Y location in one line. Then, I realized that I already had the value I was looking for in an array, at the index I was passing to the function where my processing was. So, instead of depending on the instance variable, I could simply use the value at an array location using an index I was already being passed.

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