I was wondering something. If you were to write pac-man with unity, how would you do it? I mean how would you keep the guys on the correct path?
Use AI behavior and keep the guys away from walls. So just let the pathfinding keep them away from walls. Set a distance and let pathfinding do the rest.
Make points along a path, then at each point have the ghost decide what to do. So each dot would be a point. When a guy touches it, then a choice of options. So a ghost touches a dot. The dot is 1-2-3 or 4 way. So at that point the ghost decides how to move to the next point. Maybe there are just 2 ways to go. Sense a ghost can not reverse course, then he must move along path to next point.
Something else.
I’ve been thinking about the old school games and how they would be done today. Something like tempest as well. How would you keep the guy on the track as he moves left and right and around the tunnel?
Forget all of that. Do it the same way it was done old school. Set up an array the size of the map. Populate it with array with map data. Then render each Sprite in the position provided by the map.
Great! Now I have to go look up array information!
Seriously though - would this array data be pixel/screen dimensions? Wouldnt that require the refresh rate to match the frames per second so there was no jittery movement?
Just ignore if the answer is simple to understand once Ive looked up array info.
And use grid-based pathfinding algorithms. The simplest grid-based pathfinding algorithm is that when you assign numerical values to each cell of the grid. At the first cells, don’t have numbers assigned to it. You put “1” at first end of the path, then go through every unprocessed cell, and assign to it “minimum neighbor value +1” and keep doing that untill the other end of the path had a value assigned to it. Once done, you read value at your goal and walk through neighboring cells so their assigned values would decrease in increments of one. That will result in path to the target.
I forgot what this algorithm is called, though.
Having said that pacman game can work without pathfinding just fine.
They are spot on… data structures are the key to making dev easy.
You don’t want to use Unity physics, waypoints, etc for this. Just build your level as a map. I use SpriteTile for this although I sometimes also create arrays for shadow maps as well.
It’s not pac-man but this is what I did for my last game Treasures of Ali-Gar which navigates a similar kind of level layout…
The Tempest movement I’d just do it in Unity the same as outside of Unity.
Again just a simple data structure. This time an array or list.
Basically you just create the segments and lay them out to create the shape you are traversing. The Editor would actually work well for this.
Then define arrays/lists of Vector2 positions for where the player is positioned and angle of rotation for each segment in order clockwise. When moving clockwise increment to next position in list. When moving counterclockwise decrement to previous position in list. Wrap around on both ends of list to the opposite end.
Actually I’d just draw these shapes and save them as images that would be a sprite in Unity. Then map the player positions and rotations. Enemies simply move straight from the center to the player position in the given “tunnel”. Then you can easily scale the sprite level shape up for the start and end of level zoom FX.
Those arcade games were great and hope you got to play all of them on the real actual machines.
There is a book called:
Classic Game Design: From Pong to Pacman with Unity (Computer Science) by Franz Lanzinger
ISBN: 978-1937585976
Franz Lanzinger, the author of this book wrote the Atari coin-op Crystal Castles which is similar style of maze game as pac-man. There is a GDC post mortem on his design of Crystal Castles which is very interesting. https://www.youtube.com/watch?v=qFzCONbKQJs
If you look at @MV10 's thread speed and difficulty of older games there is quite a bit of discussion of vector games.
ali-gar seems like what I am asking. So let’s say it is a 10x10 grid. On each point in the array I set up a wall or not a wall. Then I start the good guy at 1x1 and a bad guy at 9x9. How do you get it so the good guy moves through the maze from 1x1 to 2x1 to 3x1? and the bad guy too? Do you put colliders on the walls? but if you do then how do the guys stay perfectly aligned on their path as opposed to curuving around the corners? SO what I’m really asking is how do you move the guys along the paths in the 4 directions from 1 point on the array to the next?
@longroadhwy wow I never noticed (or don’t remember if I did) this Vectrosity asset. Clearly that is the way to go. Can easily design all levels as series or vectors and just draw them.
Actually be useful for all kinds of things. I will likely grab it at some point. His SpriteTile is a great 2D map editor.
You don’t use colliders. Just check the map cells directly.
So player requests to move up you check the map cell at the corresponding location. If it is a wall they cannot move. Same for down, left and right. Enemies move same way. If they come to a wall they examine options. Then they can either randomly choose an option or choose the path that heads in direction of the player. In ToA the enemies also have a 20% chance of turning when they haven’t reached a wall dead ahead and they are at a junction.
You can do this same kind of stuff in 3D as well although it sounds like your interests are in 2D.
But how do you keep the firing gizmo on the path in tempest? The firing, bad guys and all of that is easy to do. I was wondering about the path. You mentioned putting them in an array. Not sure of what this means.
So this is basically what I originally had suggested. At each point in the grid a decision is made.
OK, so maybe I said it wrong. So in puck-man you have a 10x10 grid (not really) with pellets and walls. However, the array is 100x100. So the check would be 10 times between pellets? Maybe this is where I am confused. I was thinking the checks would be made on a 10x10 grid so was confused on how to get from 1 point to the next. Is this right?
Vectrosity was the very first Unity asset I purchased. The main reason was the TankZone example included with the product which is a Atari coin-op BattleZone style game. I was also thinking of Atari’sTempest style game would be a fun game to write using that asset.
On cell atm so can’t easily make drawing etc to illustrate.
Basically imagine in Unity Editor you have one of the Tempest level designs. It could be just an image displayed in Unity Sprite.
Then you take the player object (create player sprite if do not have one). Position player on first segment. Note position. Move to next position clockwise. Document it as well. Continue moving around full shapes. There are a small number of segments to travel across in each level so this is quick and easy. And if centered at 0,0 often when doing top you will also get bottom offset and when doing left will have right. Not always but when you can use it.
This list of positions are your movement positions.
In practice is easier… just set up public Vector2 array or list in game object with monobehavior then drag player over for each movement. This will map the Vector2 position to the array (at least as I recall it should… worst case is you manually type it in).
Now you have the path defined. When player moves clockwise you increment a variable say CurPlayerPosIndex and use that get the coords of the next position to move to. For counterclockwise movement decrement CurPlayerPosIndex. When that variable (CurPlayerPosIndex) is less than 0 or >= LevelPositions.Length set it equal to other side of array boundaries. Meaning <0 becomes LevelPositions.Length - 1. And the other way becomes 0.
You can either manually handle rotation to point toward center and store array of zAngles as well OR you can simply calculate (actually Unity even has a method for it) to handle rotate to face center dynamically in your movement code.
Holy crap, I’ve been looking for that game for years!
That was like, the first game I ever played on a Windows 95 machine at someone’s house when I was a little kid
You gotta give this kid credit though, he skipped the step where we tell him to make tetris or pac man and just skipped straight to step two, he’s ahead of the class.
If the level is only 10 cells wide and 10 cells high that’s 100 cells total yes.
There are different ways you can store this data. I’d just use a one-dimensional array if I wasn’t using SpriteTile. So in this case it would be int[ ] aMap = new int[100];
When moving up you’d get current position based on player position converted into cells. Meaning dividing x and y by size of cell and probably taking into account some offset for each. Once you have player cell (aka tile) position I’d convert it into index into map array.
If player wants to move left check playerCellIndex-1, for right playerCellIndex+1, for up playerCellIndex-10 and for down playerCellIndex+10. You can of course also just do the normal row X map_width + col to get index of each check too if preferred.
Enemies do the same. Only in their case I check ahead first (unless the random 20% chance says they want to change direction). If blocked then check left and right. If only one path open take it. Otherwise randomly decide which (or move toward player). If no other option turn around 180 degrees and head back other way.
Hopefully that is fairly clear. It’d be a lot easier if I was on my laptop instead of cell.