SOLVED: Why won't some enemies recognize a collision? (Crash Course 2: Invaders)

I already posted a somewhat more detailed comment containing some unrelated info and questions over at the crash course (http://www.stencyl.com/help/viewArticle/182/) but this one question is especially dear to me:

Why is it that sometimes enemy ships don't realize they have been hit by a bullet?

I already 'fixed' this issue by killing off the bullets mere 0.1 seconds after they hit their mark (instead of instantly, like proposed by the tutorial).
But what almost drives me mad is the fact that for every enemy ship that didn't recognize a collision there were a few that did just that perfectly. I would understand if nothing worked. Or everything. But why are there inconsistencies between multiple members of the same group that are treated in exactly the same ways?

If needed, I'll post relevant screenshots of every event involved in an answer but I really hope that somebody might be able to explain this problem on a more universal level to me.

Thanks in advance and cheers,
IITH

« Last Edit: February 26, 2014, 11:32:08 am by IsleInTheHeavens »

rright0102

  • Posts: 7
I had the very same problem. My bullet would hit an alien and be destroyed, but the alien stayed. Check your game settings.

Click Settings Icon. Click Groups. Then go through your groups and make sure that Collides With is set to the group you want to detect collision with.

supadave810

  • Posts: 1
I have same problem.  My collision groups are all set.

My problem is, I have 6 enemy ships and one of the 6 doesn't detect the collision. The bullet disappears but the ship isn't hit. Now, if I spam the action button it will disappear. This only happens on the single ship. All the others work fine.

@ rright0102:
I already checked my groups in the settings (enemies collide with bullets and vice versa) and in the actor types (enemy ships are enemies, bullets are bullets). What's more, most of the time everything works just fine. If there were a problem with the groups, wouldn't there be no collision detected at all?
There has to be something that treats the collision between bullet and enemy ship differently if certain conditions are met - and I'd love to know what this something and the conditions are.

@ supadave810:
Yep, sounds like what I'm experiencing.
Did you try my 'fix' already? I would love to know if it worked for just me or whether it legitimately corrects the cause for the wrong collision detection.
For clarity I've added the events of my bullet actor.

rright0102

  • Posts: 7
My initial experience with the Crash Course was about a week go with 2.2. This morning I loaded 3.0 that same example did not work right.  I was seeing the ship destroyed, but the last bullet stayed behind on the screen. It is stopped (due to physics)

I suspect, but am not sure, that all collisions are not detected instantly. So if one object detects a collision 1st and is destroyed immediately, the other object may not get a chance to detect that collision. The order in which detection is done may not be the same for all objects. So sometimes the ship gets destroyed other times the bullet.

Adding a delay to ALL objects seems to fix this for me. Do after .01 seconds kill self on the bullet. and a .1 on the ship. One thing I think you need to be cautious of is not to delay too long otherwise multiple collisions can occur. So if the frame rate is 60 frames per second, a timer of .01 should just catch one cycle. The reason you want the timer longer on the alien ship is so that the flash effect and sound have a chance to finish.

If you have a timer of .1 on the bullet and you are counting Hit Points then you will have had multiple collisions between the objects as several screen update cycles go by before the object is actually killed. The HP value will decrement multiple times and you will wind up with one shot kills.

So on bullet I have:
when self hits  member of enemies
do after .01 seconds
kill self

on enemy ship:
Created event:
When created
set hp to 3

Actor group event:
when self hits a member of bullet group
decrement hp by 1
apply effect make negative to self
do after .1 seconds
remove all effects from self

Updated event:
always
if hp < 1
play explosion
do after .1 seconds
kill self

Thanks. That has to be good enough of an explanation for me.
I'd hoped that there were some other mechanics working in the background that I simply had missed. I don't know how I feel about having to work/code against stencyl's seemingly random nature at some points. But whatcha gonna do?

Anyhow, thanks again - I guess I'll mark this one solved.

Cheers,
IITH

Beckb

  • Posts: 72
For those of you still looking for an answer to this problem, try removing the collision shapes for the actors involved and adding them again, with a pixel or two of difference. It worked for me.

StyrofoamMagma

  • Posts: 1
Yeah, it seems that being even one pixel off can break the entire universe.  If you want to be sure, draw a 50% transparent block the same size and position as your collision shape so you can visualize how it overlaps with your sprite. 

After spending more time understanding\debugging collisions than I've spent on any previous entire game, I still haven't figured out how to get consistent collisions.  Randomly, it seems, a collision between 2 actors with 0 bounciness will come to a speed of ~9.5e-16 either immediately before or after (during?) a collision.  And also not detect the collision that slowed the actor to zero. 
The bug will disappear and let me think I solved it and rear its ugly head days later.  I've overdrawn the brain bank trying to pin it down, and work around it.  Currently having luck using a block to round speeds between -.1 and .1 to 0.  But I have no faith it's gone and am still suffering from numerous other created collision shape problems.

I was also having problems with overlapping and even just adjacent collision shapes affecting each other even though they're all sensors.  So try leaving a pixel between your collision shapes if you're getting weird results.

For those of you still looking for an answer to this problem, try removing the collision shapes for the actors involved and adding them again, with a pixel or two of difference. It worked for me.