PAcmac collision detection

I am trying to implement a game in the style of pacman , however I cant get the collision/path stuff quite right. My pacman should only be allowed to follow certain paths but when I dont want pac to be able to move crooked only up-down/left-right and follow the paths. If I use a maze (TiledLayer) the collision should be easy to set up bu how do I make sure that pac cant turn down a particular path if he isn’t eactly lined up?

Cross posting, sheesh :wink:

Mod the x and y position by the size of a tile and ensure the result is zero before allowing the movement.

So, if they’re trying to move horizontally then

ypos % tilesize == 0

must be true. This should ensure that your pacman is exactly on a tile boundary.

Kev

[quote]Cross posting, sheesh :wink:

Mod the x and y position by the size of a tile and ensure the result is zero before allowing the movement.

So, if they’re trying to move horizontally then

ypos % tilesize == 0

must be true. This should ensure that your pacman is exactly on a tile boundary.

Kev
[/quote]
but if I disallow the move they could easilly overshoot there target right?does that mean they can only move in tilesize jumps, seems like it would be jerky? ???

Let PacMan move smoothly, but yes the player might move past the opening, but then thats part of the game. Some pacman games move a tile smoothly then paused for a fraction of section then move again. This gives the player extra chance to stop pac in the right place.

Either that or make it work like this. If the player pushes down then pac moves smoothly exactly one tile downwards. If the player pushes back up at any time pac moves back to the last tile. While moving left/right do nothing. Equally horizontally. This will give the player the feel of control but actually they can only move tile by tile.

Kev

OK, I’ll give it a try. ;D

Stopping only at whole tile positions (or what you should call it) makes for the best pacman controls IMHO.