Recognizing individuals in Families

Get help using Construct 2

Post » Sat May 05, 2012 3:01 pm

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)
B
30
S
2
G
5
Posts: 7
Reputation: 5,099

Post » Sat May 05, 2012 10:27 pm

Yes, C2 will automatically pick the only specific objects involved in the collision
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Sun May 06, 2012 1:30 am

Have you read How events Work? Actions only apply to the objects that met the event, so this is not normally a problem.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sun May 06, 2012 4:32 pm

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)
B
30
S
2
G
5
Posts: 7
Reputation: 5,099

Post » Sun May 06, 2012 5:04 pm

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.Xavier2012-05-06 17:05:51
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Sun May 06, 2012 5:45 pm

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)cs2curious2012-05-06 17:47:55
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Sun May 06, 2012 9:29 pm

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

[code]+Player: collides with Hazzard
-> Hazzard: set animation to "collide"
+ Hazzard.fx = 1
    -> hazzard: spawn stoneDebris
+ Hazzard.fx = 2
    -> do something else[/code]Yann2012-05-06 21:30:27
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun May 06, 2012 11:11 pm

You can take advantage of the fact that each object has a unique UID.

[code]+--------------------------------------------------------+
|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
   +-----------------------------------------------------+[/code]R0J0hound2012-05-06 23:12:14
B
79
S
24
G
55
Posts: 4,755
Reputation: 41,273

Post » Mon May 07, 2012 10:06 am

I personally use a family instance variable to specify the type within a family just like Yann mentioned and that works fine.

B
9
S
2
G
3
Posts: 17
Reputation: 2,548

Post » Tue May 08, 2012 12:31 am

[QUOTE=Xavier] 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.[/QUOTE]

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)
B
30
S
2
G
5
Posts: 7
Reputation: 5,099

Next

Return to How do I....?

Who is online

Users browsing this forum: ETgirl79 and 13 guests