Collision detection techniques

New releases and general discussions.

Post » Thu Jan 22, 2009 3:53 pm

As someone new to Construct, I'm curious as to what more experienced developers think would be the best method for handling collision detection in a game with multiple weapon and monster types.

The most obvious method is to make an event to test between the player sprite and each monster sprite/monster weapon sprite, and then more events to deal with every player weapon sprite and every monster sprite. That's a LOT of events, especially as you add more and more weapons/attacks/monsters/monster attacks.

An alternative method I'm considering is to have just one "Monster" sprite, with different animations for different monster types, and just one "Hero Weapon" sprite with different animations, and one "Monster Weapon" sprite. What do you think?
B
2
G
3
Posts: 71
Reputation: 992

Post » Thu Jan 22, 2009 4:10 pm

Families would be the best way to do it, if you don't want to make them all 1 sprite.

http://apps.sourceforge.net/mediawiki/c ... e=Families

When used correctly, they should eliminate the repetitive code you are worried about :D
B
2
S
1
G
4
Posts: 156
Reputation: 1,612

Post » Thu Jan 22, 2009 5:43 pm

You can also use families to generalise all your different kinds of bullet and projectiles, using private variables to set how much damage they cause, what kind of explosions/effects they create, etc.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Thu Jan 22, 2009 6:16 pm

Okay, when using a family like this, say I have an enemy with an attack-on-touch value. I can use an event to detect a collision between the player and any enemy. Now how do I access the private attack value of the enemy I just collided with?
B
2
G
3
Posts: 71
Reputation: 992

Post » Thu Jan 22, 2009 7:49 pm

Hmm, good question. I would think you would want to do this:



with "Enemy.Value('damage")" instead of "0" in the first action.
Actually I guess you'd want it instead of "global('damage')" in the final action.

But you can't choose Enemy, you can only choose individual sprites.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Thu Jan 22, 2009 10:57 pm

Families show the private variables which all the objects in the family have in common. You can use the Family Manager to quickly add a variable to all the objects in the family.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Fri Jan 23, 2009 12:03 am

[quote="stainsor":zigd0a5d]Hmm, good question. I would think you would want to do this:



with "Enemy.Value('damage")" instead of "0" in the first action.
Actually I guess you'd want it instead of "global('damage')" in the final action.

But you can't choose Enemy, you can only choose individual sprites.[/quote:zigd0a5d]


You mean like this?



And just to clarify, you can enter the family name into the expression editor (in other words, manually type in "Enemy.Value('damage')" )
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Jan 23, 2009 7:14 am

[quote="deadeye":3svniq8w]
You mean like this?



And just to clarify, you can enter the family name into the expression editor (in other words, manually type in "Enemy.Value('damage')" )[/quote:3svniq8w]

Exactly like that.
And I wondered if that would work. That's good to know.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests