Detecting multiple collisions
dimsdale
Member Posts: 499
I've had a search but can't really find anything on Detecting Multiple Collisions.
I just want to know when an object is touching 1, 2 or 3 objects at the same time.
Thanks
Comments
You will need a game integer attribute. Also I believe the touch count will need to be detected by the secondary objects not the main one. The main object will only be able to tell if it is colliding with at least one of the objects. However you could have each of the secondary objects detect if they are colliding with the main object.
www.rossmanbrosgames.com
Thanks for the reply, but you pretty much lost me sorry
Create a global integer attribute.
Place a rule in your actors that says, when collide with specific actor, change integer attribute to integer attribute +1. This will count how many collisions there are.
As Rossman points out, there are some limitations to this approach, namely that it only really works when secondary actors are colliding with a main, say a hero being hit by bullet actors. You'll need to place the count rule in the bullet actors because each can detect their own collision, but the hero might not be able to detect multiple collisions with bullets if they happen at the same time.
If you're trying to do this with multiple different actors then the count will not be accurate.
Basically, if the hero is hit by a bullet and a second bullet hits him while the first is still touching him, it won't be detected. This is because the rules are differential, looking for a change of state. So, going from 'overlapping with bullet' to 'overlapping with bullet' registers no difference and won't activate, even if it is a different bullet. You need at least a split second in between when the state is 'not overlapping with a bullet.'
So for example, you can make a:
game.bullet_hits
attribute, which will be connected to both bullets and the hero in the following manner.
In the bullets:
when: overlapping with: hero, change attribute: game.bullet_hits to: game.bullet_hits + 1
In the hero:
when game.bullet_hits > 0, change attribute: self.health to: self.health - 1 AND change attribute: game.bullet_hits to: game.bullet_hits - 1
thank you for your help.