Monday, March 17, 2014

Moving Platforms and Collisions

I've been working hard since the last update on getting my moving platforms to work in the game engine. This didn't necessarily have to be such a difficult task, but I wanted a single moving platform object that was general enough to be used as an elevator, a door, or any kind of moving platform moving along any arbitrary path.

After some significant time thinking about how I might implement this, I was getting discouraged. It seemed like generalizing the problem was going to be way more work than it would be worth and that it might be easier to simply create different objects for vertically moving elevators, horizontally moving platforms, sliding doors, etc. This would have been much faster to code, I think, but it just felt so inelegant, I couldn't bear it.

I did a lot of reading through the Game Maker forums looking for hints on how to find a solution to this problem. One big advantage to making a game inside a familiar genre is that most design problems have already been solved by someone else, so my hopes were high that I'd find a solution without too much trouble. Not so.

Now I'm sure others have solved this problem, but I couldn't find anybody who had also shared it publicly. I then dove deeper into Game Maker documentation and churned out my own solution. Actually it ended up being far simpler than I imagined, and far simpler also than hard-coding all the different moving objects in my game.

If any other Game Maker developers out there have questions about how I did this, feel free to contact me. I'll help if I can.

Here's a short video showing what I have so far:


I still have some work to do with moving platforms and collisions. Right now vertical and horizontal platforms work 99% correctly, but if the platform path is arbitrary (diagonal, curved, etc) then my collision code no longer functions correctly. That's what I'll be working on next.

No comments:

Post a Comment