Hi.I made a game.It has tiledmap and polygons for collision detection.Apparently whenever I run into a polygon I get stuck.Hope someone can help me with that.I read from other topics but couldn’t get it to work.
Source
I am planning to make this a small,2 player permadeath survival game.
You’ll need to show us the polygon collision part of your code only, and also tell us a little about it so we’re not lost.
http://therebegeeks.com/wp-content/uploads/2012/05/i-know-that-feel-bro.jpg
Basically, when you move the player and there is a collision, you also need to move him to the nearest free position, otherwise it’ll really get stuck.
It is easier to implement if you are working with squares and few collidable moving entities.
Yes. It helps to think of it that he may never go into a situation where he is overlapping an object. Instead, when he wants to move, if that movement would cause him to overlap, only move him up until the collision. So before changing his position, you should see if the new position is valid first. Then you’ll be fine.
Here are some pics of game with little descriptions
Right now as you can see,everything is made out of squares(tiled map) and game should have later few more moving entities(2 players and some creatures to kill).
I dont know how to check to see if tile is free to move on.
You can make a boolean method based on a X and Y position (in this case, your player entity position plus how much he moves every iteration), checking if there is something to collide with. If it returns true, it means something is already on that position.
I came up with my own solution.I made 4 separate polygons(straight lines) for each direction and made them detect wether something is blocking from moving it in that direction or not.Right now it works beautifully.
Thanks for suggestions though.