Issues with Game Lab and colliders

Link to the project or level: Game Lab - Code.org
What I expect to happen: Player sprite to collide with the zombie sprite.
What actually happens: The player sprite is going through the zombie sprite and it is not sensing it.
What I’ve tried: Detecting whether it is sensing the collision. Tried “is touching” and “collide”, and neither work.

@ben.tomlinson,

Thanks for your question! Looks like a fun game and we are happy to help!

A few issues I see with your code. First of all, I only see a collide statement with the player and the walls and with the right facing bullet and the zombie. I don’t see any collision code for the player and the zombie at all.

Also, when you call the bullet code, it will only run once and then immediately check for the collision because the bullet code is only called when the arrow key is pressed (and the player is facing a specific direction). By the time the bullet gets to the zombie, time has passed and the collision code won’t ever run (other than right when you fire). The collision code probably needs to be in the main “draw” function rather than in the “bullet” functions so it is called repeatedly and not just once.

Finally, because you are creating the bullets inside the bullet functions, each time you send a bullet, you are creating a new sprite (but naming it with the name of an old sprite). This could cause multiple sprites to exist at once with the same name (bullet). This will most likely result in unpredictable behaviors.

It’s better to create the sprites outside the draw loop (and make them invisible and perhaps even off the screen somewhere) and then move them where you want them and make them visible once fired. That way, you may have more than one bullet sprite (bulletL, bulletR, etc.), but they will have different names and will be more predictable.

Let me know if any of this doesn’t make sense and I am happy to look at it closer.

Good luck!

Mike

1 Like