Make instances within families react differently?

Get help using Construct 2

Post » Wed May 15, 2013 12:10 am

How do I get it so I can have 1 family for 5 different enemies, but have each individual act differently. Or say, pick family instance EXCEPT Enemy 1.

Example:
I want enemies to react differently to being hit.
-Some enemies I want them to do death animation on hit.
-Some enemies I want to do a hit animation, and reset their attack counter
-Some enemies I want to not even flinch on the hit.
-I want ALL enemies to get -50 HP, EXCEPT Enemy 1

I hope I explained it well. Any ideas?
B
32
S
4
Posts: 405
Reputation: 3,219

Post » Wed May 15, 2013 12:23 am

You have a family called ENEMY. There is a wolf, a vampire and an alien that are all enemies. Give the family an instance variable called "Name". Then you can give each instance an appropriate name. So if an ENEMY is hit, you can pass along the NAME of that specific enemy which will determine what kind of enemy. You can call a function and pass the name of the ENEMY as an arguement for that function for the function will know what to do.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Wed May 15, 2013 12:41 am

"You have a family called ENEMY. There is a wolf, a vampire and an alien that are all enemies. " Thought this was going to be the beginning of a bar joke   



hmmmmm i think I see. I could say if EnemyFamily is hit AND EnemyType =/= 'Wolf': -hp and Set State "Hit".
Then have a separate sub-event that says
if EnemyFamily is hit AND EnemyType = 'Wolf': -hp and Set State "Angry".

Ill try it out to see if it works
B
32
S
4
Posts: 405
Reputation: 3,219

Post » Wed May 15, 2013 12:52 am

@bscarl88

Pretty much that is right. But instead of have the condition if EnemyFamily is hit AND EnemeyType <> "Wolf": -hp, you could just make another family instance variable called HitDamage. Then give each instance its own HitDamage which will determine how much damage they receive. Set the Wolf's to zero if you don't want him to receive any damage.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Wed May 15, 2013 4:39 am

But that would mean that for every action, I would have to say If enemy is hit and enemyType = Alien, do this. or for every individual enemy type. I think if I want my enemies to react differently to every time of object, then I will have to do it individually
B
32
S
4
Posts: 405
Reputation: 3,219


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests