Enemy actor & Bullet actor set to both destroy when other overlaps/collides, but only one does. Why?

findmattgamesfindmattgames Member, PRO Posts: 100
edited April 2014 in Working with GS (Mac)

Prototyping some gameplay last night...

So a "bullet" actor is spawned and sent flying towards an "enemy" actor. Bullet actor is set to destroy when overlapping/colliding with enemy. Enemy is likewise set to destroy on overlapping/colliding with bullet. Only one of them destroys. Why? Am I missing something?

I tried this logic in another full game of mine and saw this behavior so I started a brand new game from scratch to try it alone. Same problem.

In the video you'll see the bullet (small grey box) always passes through the enemy (larger blue box). Enemy destroys correctly. Bullet doesn't.

Also attached pictures of the behaviors.

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited April 2014

    @findmattgames, if you look at the layers tab of your scene, you will see all of your actors. At run time they get processed/evaluated from bottom to top during one game cycle.

    When you spawn an actor, it gets created somewhere in this stack depending on your settings in the spawning actor (in front of actor or behind, bottom of layer or top). If you were to play with this oreder you may find that the bullet destroyes but not the ship.

    This is because the bottom most actor of the two gets evaluated, found to overlap and then destroys. When the code of the upper actor gets processed the overlap rule is no longer true as the other has been destroyed.

    You can solve your specific situation by wrapping the ships destroy in a timer (after 0.04 run to completion). This will keep the ship alive for one extra code cycle, allowing the bullet to detect it. Rule of thumb is that a code cycle is usually 0.02 seconds long.

    You could also change the ships alpha to 0 immediately, to hide it on impact, if it looks weird hanging around for an extra frame.

  • findmattgamesfindmattgames Member, PRO Posts: 100

    Wow @Hopscotch‌ thanks for such a thorough answer. Makes perfect sense. Works like a charm. I actually set a delay of 0.04 on both and interpolated to alpha immediately for both. Looks perfect. Thanks again!

Sign In or Register to comment.