Thursday, December 6, 2012

Game Maker Tip: the Collision Event

Hello, dear readers!  I have been busy with life and school, and haven't had much time to think about, let alone update, my blog.  This ends today!  While I take a quick break from working on my final project for my Rapid Prototyping course, I shall take a moment to cover something I've learned about the collision event in Game Maker.

So I'm making a tower defense game, which means I need towers, right?  But wait, every time the enemy collides with a tower, they both die right away instead of dueling it out!  I have the enemy programmed to stop walking and hit the tower every x steps, but it's not working.  What's going on?!

The short answer is this: the collision event works differently depending on whether the object you're colliding with is solid or non-solid.  If you mark that object as solid, Game Maker will push the moving object back to its pre-collision position after they touch, as if the object actually bounced back slightly like it would in the real world.  If it's not a solid object, it'll leave the two "on top of" each other, meaning the collision doesn't really stop until something moves away.

What does this mean for my tower defense example?  Well, if I mark my towers as solid, the enemies will "bounce" back slightly when the two collide and will be able to stand there hacking away at my defenses.  If I  leave them as non-solid, the two will pretty much get stuck together and constantly recall the collision event until they both die.  Fun stuff, eh?

I hope this helps someone out there, as it gave me a lot of trouble while I tried to get my game up and running.  If you have any questions, concerning the collision events or just Game Maker coding in general, feel free to leave a comment.  I'm still pretty new to the program, but I might at least be able to point you in the right direction.  Happy developing!