non_tech_guy Posted September 25, 2014 Share Posted September 25, 2014 Hi, I read a really good article about the ghost movent in the original Pacman arcade game and thought building a Pacman game would be a great way to learn to use the awesome Phaser framework. The article can be found here - http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior My question is....Is there a way to know which side of your object has collided with the walls in your game? In my case when the ghosts collide with the walls in the game they need to make decisions on which direction to move next. Thx. Link to comment Share on other sites More sharing options...
lewster32 Posted September 25, 2014 Share Posted September 25, 2014 In the collide callback, check the ghost.body.touching object to see which side is touching:game.physics.arcade.collide(ghosts, walls, function(ghost, wall) { if (ghost.body.touching.left) { // ghost is touching the wall to its left } if (ghost.body.touching.right) { // ghost is touching the wall to its right } if (ghost.body.touching.up) { // ghost is touching the wall above } if (ghost.body.touching.down) { // ghost is touching the wall below }});However, I think Physics may not be the best approach to a Pac-Man game, as the game is based on a grid layout. There are much more efficient and far less problematic ways to approach grid-based games and I can almost guarantee you're going to run into problems with physics in such a game, such as the ghosts getting stuck on walls and colliding with things which they shouldn't be colliding with. It'll take a bit more effort to write a manual grid-based movement and collision routine but it'll be worth it. non_tech_guy 1 Link to comment Share on other sites More sharing options...
non_tech_guy Posted September 25, 2014 Author Share Posted September 25, 2014 I guess since the objective was to create a game and play around with the physics I should probably look at building another game. Thanks for the advice. Link to comment Share on other sites More sharing options...
lewster32 Posted September 25, 2014 Share Posted September 25, 2014 To be clear, Arcade Physics was designed with platform games, classic shoot-em-ups and other such games where freedom of movement is one of the primary concerns. It allows for developers to drop in a fairly lightweight and simple physics simulation so that stuff like gravity, velocity and basic collision detection as a result of these 'forces' can be implemented quickly. The simulation however is both fairly crude and yet also overkill in a lot of situations - and while at a glance it seems like it'd be fine for puzzle games, grid games and so on, the fact that it operates in a somewhat realistic physical way causes it to be very inappropriate for such games. Just like in the real world, chaos reigns supreme in any physical system; small deviations quickly grow, resulting in large effects over time, and cause increasingly large and seemingly illogical problems. Link to comment Share on other sites More sharing options...
rich Posted September 25, 2014 Share Posted September 25, 2014 I agree, I wouldn't use Arcade Physics for the wall collision as a simple grid will be much more effective. However you could still use it for checking pacman vs. ghosts overlap and pacman vs. pills overlap. It would be fine for that. Link to comment Share on other sites More sharing options...
Recommended Posts