Problem with Multiple Collisions on one actor not triggering rule multiple times
Hi Everyone!
I couldn't find an answer on this, apologize if it was already answered somewhere in forums.
I have a game where I'm shooting enemies with bullets. When powered up, the player shoots multiple bullets at the same time side by side (think vertically in a shoot em up game). The enemies have health bars, and for every bullet hit I lower the health of the enemy it collides with. For some reason, however, whenever I am powered up and shooting two bullets at the same time, if both of those bullets hit the enemy at the same time, it only registers the enemy's health loss for one bullet, and not both, although both bullet actors do get destroyed.
O <-- enemy
** <-- bullets
O <-- player
On bullet collide I lower enemy.health, but this is only triggering once so although both bullets hit, it only lowers the enemy's health once and not twice. Is there a problem with multiple same actors colliding with an actor at the same time not triggering the rule X amount of times?
Thanks in advance!
Comments
Use two separate actors for the two bullets being fire simultaneously.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Hi Armelline! I am doing that already -
I have the following - when power level 2, I have 2 separate "Spawn Actor" behaviors, whose only difference is their X position relative to the actor when spawning.
Is this a bug?
Take example:
Actor A, Actor B, Actor C
Actor A spawns 2 separate actors of type Actor B (using 2 separate Spawn Actor behaviors, one after another).
Rule for Actor C that when Actor B collides/touches Actor C, subtract 1 from health.
When both separately spawned Actor B simultaneously hit Actor C, the rule on Actor C only occurs once, and not twice.
Am I missing something? Any help would appreciated, thanks!
I attached screenshots, Arrow is of tag Projectile.
It's not a bug. The collision rule needs to be in the projectile actor. Rules only trigger when their status changes from false to true. So if you have a player/enemy actor being hit (collided with) by a projectile actor, that collision rule will then be true. If another projectile actor hits that actor right after that, the rule is still true so it will NOT trigger. The rule would have to first be false again (no collisions) in order for it to trigger on the second collision. If you move the rule to the projectile actor instead, it will trigger when that actor collides with the player/enemy actor no matter how many other projectile actors have collides with the player/enemy because the rule is specific to each projectile actor.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks for the reply tatiang,
I see where you're coming from in terms of the rule staying true.
I have two questions I was hoping you could help me answer:
It's quite hard to know what enemy the bullet has hit once you put the rule on the bullet. It's one of those problems that have stumped me on a number of projects.
I think what @Armelline may have meant is spawn two different bullet actors. So if you want to spawn bullets at the left and right of your actor then create an Actor called Left Bullet and one called Right Bullet. Spawn both in the same way you're doing now and have 2 rules on your enemy actor. One that says if collides with left bullet, and another that says if collides with right bullet. He might not have meant that but that would be one solution. You could have a 3rd actor bullet for your normal one shot weapon.
I put these 2 rules in a group to make the getting hit effect instead of going into each enemy actor. This will recycle the rule and force it to trigger every amount of time i want. I put alpha cause I like the color alpha to reduce , but you can put a bool instead
Group
if collide with enemy and self color alpha = 1 then change game.health to game.health-1 and change color alpha to 0.5
if color.alpha is less than 1- after 1 second change color alpha to 1
or if you dont want alpha you can put a boolean instead or any condition you want, or just put the rule in the enemy instead as they said
@IceBox your example reduced game.health which would probably be the players health. You wouldn't want to have a game attribute for each enemies health
@KevinCross Oh I thought he meant the player ! my bad
Why not do it with whatever triggers your powerup to shoot two bullets
If game.powerup is true spawn 2 bullets if not spawn 1 bullet
In your enemy actor
if actor overlaps or collides with projectile
inside create a rule if game.powerup is false change self.health to -1 otherwise change self.health to -2
This should work without worying about tracking health unless your bullets are far from each other in which one of them might miss
Thanks for the suggestion KevinCross! I ended up going this route, works like a charm! I had to add a few actors and more rules for each enemy actor but it shouldn't be too much overhead in the long run I hope.
Thanks for the suggestion Icebox! I would have preferred to do it this way to minimize hard-coded actors/rules, but unfortunately the bullets can miss in my scenario
Thanks for all your help everyone! Nice to learn deeper how GS works.