Pac Man movement vs Maze

Hello, sorry for my bad English (I speak French) (google is my friend!)

I would like pacman to move while being centered in the maze and avoid running into a wall and then backing up.

I don't want pacman to be able to turn left or right if there is no path in that direction.

I have tried different approaches:

  1. Go for the wall (color) and go back
    problem: works but after going into the wall, if I turn left or right, I am not centered in the path ...

  2. Have an invisible sensor attached to the front: when the sensor touches the wall (color), pacman stops
    problem: some intermitent lag

  3. Sensor left and right to see if we can turn
    problem: some lag

According to you, what's the best approach?

Thanks in advance !

hey welcome to the snap forums

try making a hitbox costume bigger than pacman that perfectly fits the size of the maze, then use this hitbox to determine collision. when you want to detect something 5 pixels right of pacman, move the costume 5 pixels to the right and do what you want, then move it back 5 pixels left to get it back to the previous position. you can do the same for the other directions. then at the end of the script, put the costume back to normal so when the screen refreshes it will show pac-man.

or you could use a 2D table or something to represent walls and stuff and then calculate pacman's position on the list, then you can use this info to determine collision. i think this is the least expensive solution, though it is less intuitive than the solution listed above.

I will try this thank's

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.