I decided to look into collisions again, and decided that for this game a true physics based solution was a bit of an overkill. So, instead, before objects move, they "Sweep" their collision volume ahead of them and try to see if it runs into anything. If it does, then they cut their movement short (or attempt to slide).
You should be able to run around and not leave the map area. The ghosts should also act as barriers to themselves (not likely to be seen) and the player.
It isn't much, but it's a start!
I've also noticed that my "TMX Map" solution is way too slow. It drops the FPS from ~500 to ~50. That's no good. I think it has to do with creating a GameObject per grid location in the map. I'll have to look into optimizing that next or the game won't be very responsive. :)
I've added a fragment of the code that does the static collision test. It isn't anything super great, but it gives you an approach to doing collision that is more in control of the scripting engine versus the PhysX engine. It's basically sweeping the collider ahead to see if there is a collision and then changing the walk vector apporpriately. I have a set of options that an object can do by overriding the "HitOther" method and returning a value from the enumeration.
It's not anything super, but I figured it might be of interest to someone that is struggling with their own collision code in a 2d game.
You can find the fragment of code on the Free Stuff page.
Enjoy the demo by clicking on the "read more" link!
#1 and #2 named him: Bryan, the ghost pew'er!
ReplyDelete