Movement for pacman

New releases and general discussions.

Post » Thu Sep 02, 2010 12:31 am

I am trying to make a pacman game. How do I get my ghosts to move in straight lines and then moves up or down if they hit a wall. When I used bullet, they went through all the solid walls.

Is there a manual page that describes all the behaviour options?
B
4
G
2
Posts: 42
Reputation: 811

Post » Thu Sep 02, 2010 6:59 am

use an "on collision with wall" event to change the ghosts direction.

No manual yet, just the wiki, the forums and chat.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Thu Sep 02, 2010 7:40 am

Bullet always moves forward, and forward is dependent on the sprite's angle. By default, sprites face 90 degrees, or right. 0 is up, 180 is down, and 270 is left.

You can keep bullet on the ghost, and manually do this with events. On collision with wall:

If current angle is 90 or 270, randomly change angle to 0 or 180.
Else if current angle is 0 or 180, randomly change angle to 90 or 270.

That's all. Please keep that else in mind, it is important. If you start at 90 degrees and go through this block without the else, the first event would change you to 0, and the second would change you back to 90, the else makes sure only one of them fires, instead of the possibility of them both firing in sequence like that.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Thu Sep 02, 2010 9:18 pm

How would I set an angle to a random option of 90 or 270?
B
4
G
2
Posts: 42
Reputation: 811

Post » Thu Sep 02, 2010 11:46 pm

You could always try Rojohounds pathmovement plugin.It's ideal for a pacman type game.
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Fri Sep 03, 2010 12:38 am

Thanks for that but I am doing this for a school lab and I want to use only the default install.

I've basically got the ghost movement right but have a problem when it moves alongside a wall. Even though I've aligned the blocks for the wall the Ghost appears to collide with it and then make a random turn i.e. it won't travel next to a wall for long.

This will make more sense if you run my file a few times: [url:203g9zbm]http://www.rosmini.school.nz/downloads/pacman.cap[/url:203g9zbm]
B
4
G
2
Posts: 42
Reputation: 811

Post » Fri Sep 03, 2010 1:10 am

[quote="abasel":2x34uzq2]How would I set an angle to a random option of 90 or 270?[/quote:2x34uzq2]

90+(Random(2)*180)

I believe Random(2) will give you 0 or 1, unless they changed the indexing on me, so that will either give you 90 + 0 or 90 + 180. 90 or 270 respectively.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Fri Sep 03, 2010 1:42 am

Thanks, that's great... I've made the change but now if you run my program for a while you will see that the ghost sometimes goes through the wall.

[quote:2527u6h2]This will make more sense if you run my file a few times: [url:2527u6h2]http://www.rosmini.school.nz/downloads/pacman.cap[/url:2527u6h2][/quote:2527u6h2]
B
4
G
2
Posts: 42
Reputation: 811

Post » Fri Sep 03, 2010 4:27 am

You are missing two things that the AI needs to function properly. Also, it would really help if the ghost was the same size as the tiles.

First of all, you need to keep track of the angle of the ghost, so you know which direction it's moving in. Second of all, you need to check in the direction you're about to move with an overlap at offset check, before you move in that direction. Right now you change directions at random without making sure there's a wall in that direction first.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Sat Sep 04, 2010 12:28 am

random(2) will give you 0,1 or 2 from what I've seen so far. Maybe that requires a little messing around with .caps.
B
2
G
2
Posts: 42
Reputation: 734

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests