Search Unity

How would you do pac-man?????

Discussion in 'Editor & General Support' started by RandomCharacters, Sep 16, 2016.

  1. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    LOL! No but it just seems odd for it to be in Editor & General Support when it is clearly focused on 2D game development.
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    It has been decade(s) since I played it. I've never played a non coin-op version - so awhile. :)
    Its one of those games that was just fun - and gave gratuitous feedback (kind of like Void Invaders).
    I always liked that game but really have no desire to make a game like that.

    What kind of AI did it really have? Just a flocking type AI with some randomization for position/speed as far a I remember.
     
  3. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    What?! :eek: The Robotrons used highly advanced AI far beyond anything we see today. Remember these things were real! lol

    Okay that is probably a stretch. But the Robotrons did have AI about as (and probably more so in some cases) as advanced as we see in action games today. Distinct behaviours in a sense. They had their own agenda. The game may look simple (and is for the most part) but as was often the case back then the game design and programming and such made up for the presentation to create an interesting gameplay experience.

    Relevant info starts at 1:36 mark
     
    Last edited: Sep 17, 2016
    theANMATOR2b likes this.
  4. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    OK, so the colors that rotate in robotron, I've always wondered about that. See it as wall in Atari VCS adventure where you get the eater egg (which was not 1st easter egg as some say).

    I am guessing here. they are rotating colors based off of the 16 colors they had, so red is 255,0,0. Then it seems like some kind of fade to black, then a cut to a new color. Anyone want to take a jab?

    I think the best thing about robotron is the SFX and then the color and then the duel joysticks. However, take away the SFX and it's a completely different game.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's just cycling through the 16 colors in order of brightness.

    --Eric
     
  6. KnightsHouseGames

    KnightsHouseGames

    Joined:
    Jun 25, 2015
    Posts:
    850
    Yep. And he loved it.

    He was a very simple man..
     
  7. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Did not play the Robotron coin-op version very much. Played the Atari 8-bit computer version quite a bit. In least in that 8-bit version Atari included a plastic holder for two Atari joysticks which worked very well for conversion. I never saw any of the other conversions.

    The two joystick controls is what made that game in my opinion. I think Stern's Berzerk and Frenzy would have done better if they had similar controls.

    Have you looked at GDC Robotron Postmortem? The game creator talks a bit about AI and motivation of the game ...

     
    theANMATOR2b likes this.
  8. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Which wireframe rpg are you thinking about? Did you ever play Atari's vector graphics coin-op Major Havoc?

    Speaking of Tempest here is a good pictures of all of the enemies here and it would work well with Vectrosity.

    http://strategywiki.org/wiki/Tempest/Getting_Started

    I was playing with TankZone (Vectrosity's example) a bit and just changing the colors which makes it a more interesting game. In my case I changed the mountains to blue, the normal tanks to yellow and the supertanks to blue and so forth. Just mainly a test for how colors would work in Tempest style clone. I think level 11 in Tempest (which is just a flat grid) would be best level as a first test.

    For controls the spinner works well since it emulates a mouse so it is fairly easy to integrate

    http://www.retroarcadeslive.com/spinfeat.asp
     
    Last edited: Sep 18, 2016
    GarBenjamin likes this.
  9. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    In the 1994 SCES video I posted on a earlier message, jeff Minter said he was going to do Major Havok 2000. he never did. That was a cool game.
     
  10. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    I got SpriteTile, read the instructions and opened your pac-man file. The following was in the readme.txt. I looked and it is an array of size 0. It doesn't say missing, just a sprite list of size 0. What do I drag there again? I am not sure what you mean.


    "This needs SpriteTile to work! After importing SpriteTile, check the Plugins/SpriteTile/Resources/TileManager file and make sure the TileManager is hooked up properly (no missing reference) before doing anything else. Just assign the reference from TileManager in the SpriteTile dll if necessary"
     

    Attached Files:

  11. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    By wireframe RPG I meant the display of the dungeons at that time. In the very early days it was only lines. Which actually looked very cool I thought (and still do) kind of like a pencil sketch.

    The main games I remember that used this style for the C64 were of course the first Wizardry game, (probably the most well known), Questron, The Standing Stones (I think that's what it was called... been a long while now. I think Epyx or maybe Electronic Arts made it though) and some generic game called simply Maze Master. That last one may have been one of the thousands of games I checked out in the PD from BBS at the time. I just don't remember anymore. I say generic meaning just the name. I liked the game best as I can remember.

    The names of some of them might be wrong but I *think* they are correct. Questron I am sure about because I really liked that game and everything was wireframe. Even the chests, monsters, etc. Outlines. Well for the dungeon crawling view I mean. Most of the game was like top down terrain view as most were around that time.

    I also remember the legendary Oubliette. Probably the first and greatest of the RPGs of that time as far as spinning the lore of a great dungeon below the city. And adventurers tested themselves exploring the monster filled ancient dungeons trying to find treasure. Time may have butchered that but it is the gist as I recall. Some ports of it switched from the 3D perspective to a top down view IIRC.

    I don't recall ever playing Major Havoc or even seeing it in the arcades I visited.
     
    Last edited: Sep 19, 2016
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Start over from scratch, but this time when importing SpriteTile, don't import the TileManager asset, since that will overwrite the one in the project. (Actually that shouldn't even be in the Asset Store download, it's just an empty file, sorry about that.)

    --Eric
     
  13. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Yes, that worked. So I got the pac-man demo up and running. I have just read the instructions and all and will give a mini review here.

    1) You need a how to guide. Take the gem game and make up a document. Start from scratch. This could even be a video. Show how to set up the map, how to move, how to trigger and so forth. The instructions are more of a engineers reference tool. Just go from a blank project to a finished one. Or use pac-man with ghosts and collisions. You don't need AI. However, if they are not game objects, then how does one write AI for them?

    2) If using the gem as a guide, include firing a projectile as a guide.

    3) You should have scripts for movement and such (in c# not javacript). Then all one has to do is attach them (like in platformer pro).

    4) Explain a few things better like where is this map? on the canvas? if they aren't game objects, then how do I do things? You have an api, but does that mean I can't code normally? There are a lot of questions I have now after reading the manual. if I have them, then other will too.

    5) You mention shadows of buildings on page 19, but never show how to do it. How do you overlap tiles to create shadows?

    I really liked what you did here, but it seems like it needs a little more explaining on how to do things whereas the instructions were more just reference.
     
    Last edited: Sep 19, 2016
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You have access to the level with GetTile/GetCollider/etc., so you can use those.

    There isn't a canvas; the map exists in memory.

    That depends on what you mean by "code normally". ;) Using an API is coding normally, as far as I know. I'm not really sure what the question is.

    Best to load the GemHunt demo and look at the tiles and level. Tiles don't have to be confined to the grid; if the grid is sized for e.g. 32x32 pixel tiles and you make a 96x96 pixel tile, it will overlap all the tiles around it by one full tile. Setting the pivot point for the tile allows you to move it around relative to the tile center.

    In any case, docs can't cover all possible learning styles; that's what support is for, so you can ask questions if necessary. Should really be in the SpriteTile topic rather than co-opting this one though.

    --Eric
     
  15. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    So pac-man is 28x36 tiles with each tile 8x8 (224x288). loocking at pac-man and the ghosts it seems they are larger than the tile. Sense the walls look smaller than full tiles, then the guys can be larger it seems and look right.

    1) So in tilesprite would you make pac-man oversized (say 10x10)?
    2) What then happens for collision? If a ghost is 1 tile off and tries to go to pac-man tile, then is the collision on the tile? I mean using collider they must touch each other but it seems on the tile method, if the guys were smaller than the tiles then pac-mac would die without touching a ghost. If bigger would it have the pac-man bug where the ghosts sometimes go right though pac-man?
    3) With the fruit at the bottom right (4 tiles), would you just make the texture 16x16?
    4) What if you had a really big maze with a moving camera. Pac-man goes all of the way left, is there a way to have him get to the right sixe of the map? a wraparound?

    http://www.pacmandossier.com/

    http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
     

    Attached Files:

    Last edited: Sep 19, 2016
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make the sprites whatever size looks right. Since I was doing it quickly, I made the pacman sprite the size of the tiles, realized it was too small, so just scaled it up. I would just use standard 2D collisions for pacman/ghosts; a box collider is fine. I'd make the fruit tile whatever size is right, yes. You can make whatever behavior you want; I didn't do the side tunnel wraparound, but one approach could be to set trigger values at the appropriate spots and use GetTrigger/GetTriggerPositions to move to the other side. Make the map one column larger on the left and right to avoid out of bounds errors.

    --Eric
     
  17. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for the clarification. I remember the Wizardry name when it was on the Apple II but never played it. It was never ported to the Atari (8-bit) computer line as far as I know (which was the computer I had).

    @wheretheidivides

    That would have been great.
     
    Last edited: Sep 19, 2016
    GarBenjamin likes this.
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds about right, but you can use the preview function in the TileEditor to see the map in the scene if needed. You can move objects around as usual and use the Get* functions to say "so, what's going on with the tilemap at this position". Which is in fact what old hardware commonly did, where it was tile-based but you also had a certain number of sprites you could move around freely.

    1) Yes, probably simplest to extend the map and duplicate the edges from the opposite side (as much as necessary to fill the screen; e.g. if you can see 32 tiles at once, then 16 tiles for the edges should work).
    2) Yes, you could use trigger values for that.
    3) Yes, depending on what you're doing.
    4) Sounds about right.

    It's handy for any kind of tiled game really...RPGs, side scrollers...PacMan. :) By the way, here's an updated project with side tunnels working, using triggers. I was also thinking about the flashing walls effect when clearing a level, and about how indexed color hardware can be easier for some things. The obvious way to solve that on modern hardware is with a shader, but then you have to write shaders. You could have an alternate tile set with white walls and flash them by using SetMapTileset, but that's a little wasteful and you'd be hard-coding the colors into the tiles. Or, think outside the box. ;) So you can finish levels now and it flashes the walls.

    --Eric
     

    Attached Files:

  19. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Does the tile map always show beneath the hierarchy stuff or can you change the order? Are their playmaker actions for the commands (hint)?

    Also, all of your examples are in javascript, but most people use c#. Very tough to follow.
     
    Last edited: Sep 19, 2016
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    All the code in the docs is C# and Unityscript (which is not actually Javascript despite Unity calling it that), some of the examples have C# versions. In any case Unityscript and C# are mostly similar; the code can be used as C# with minimal modifications. The tilemap is sprites, so however you have layers set up is what the order is.

    --Eric
     
  21. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    The pac-man scripts are all javascript. I tried to convert over to c# but am not a coding expert. There are some errors. Here they are. Maybe you could fix the minor erros. That way people can get both. I do think unity will drop support of javascript in 1-2 years which is why I try do everything in c# or playmaker.
     

    Attached Files:

  22. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I have not tried any of the automated conversion tools myself but this unityscript to C# tool looks interesting. The PDF manual is 42 pages and it looks like it covers quite a bit. It might be a useful tool if you have a large amount of code to convert.

    http://forum.unity3d.com/threads/csharpatron-the-definitive-unityscript-to-c-converter.259847/
     
  23. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Yeah, I have one of those converters and they just don't work. My previous message had c# scripts that I converted by one of them and it just does some. So yeah, I used one and the pac-man scripts are fairly short. And they won't give you your money back if they don't work.

    I decided to start pac-man from scratch. I went pixel by pixel on all graphics and did the maze and all. I have no programmed anything yet as I was trying to figure out how spritetile works. If I get it to work, I'll just convert it to a new game. This is a good learning tool. This characters are in their tiles, but 1/2 off. I just put them in the map but I guess they need to be unity sprites then they will be centered.
     

    Attached Files:

    Last edited: Sep 21, 2016
  24. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    So I think I have the graphic part of sprite tile down. Here is maze 1 of ms. pac-man. I did this in a fraction of the time from pac-man. Now I have to figure out how the c# api works to move them around.
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      41.4 KB
      Views:
      43
  25. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I did not think any of those automated converters would be able to solve all possible combinations of ultrascript code. That manual (42 page PDF) version that I looked at it was very good explanation of the use cases that it can solve and not solve.

    One case from the user manual I thought was interesting was ... Unityscript's untyped Array class has no direct equivalent in C#. There is no way to auto convert something like that.
     
  26. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    They have really good discussion from GCC (the creators of various Atari coin-ops (e.g. food fight and quantum and the super missile attack add on kit for Missile Command)) on how they created MS PAC-MAN. They did a GDC postmortem of MS PAC-MAN also but I did not see anything online. The tool they used for character creation is so interesting.

    This is from MIT lab since some (maybe all) of the GCC developers were MIT students. An interesting world of reverse engineering ... I always wondered how they handled the lawsuit with Atari over Super Missile Attack and they have some discussion of that too.

     
  27. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    I've watched these videos you posted and all of them are awesome. Is there a website with more of these or something?
     
  28. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Atari arcade coin-ops is my main interest for postmortems so those are usually the ones I look for. But most coin-ops are usually very interesting to learn about the hardware and software they used to make the game.

    The are others from MIT which can be found at this site. "Push Button: Examining the Culture, Platforms, and Design of the Arcade"

    http://gamelab.mit.edu/pushbutton/

    Sometimes just searching youtube with postmortem and a specific game can work also.

    The GDC has been putting some of their postmortems on their GDC youtube channel. Some are only available on the paid GDC vault subscription.

    Here is the GDC youtube channel if you want to look for more.

    https://www.youtube.com/channel/UC0JB7TSe49lg56u6qH8y_MQ/videos

    Here is another GDC postmortem on the Atari coin-op Gauntlet by Ed Logg (who also created Asteroids coin-op game and many others).

     
  29. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    I just watch the video and the book sounded familiar. I looked in my desk and whalla: I have it. Must have bought it when it first came out. It's basic and simple, but is aimed at beginners of unity.
     
  30. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Is the code for that book [Classic Game Design: From Pong to Pacman with Unity (Computer Science)] in C# or UltraScript?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    "Unityscript".

    --Eric
     
  32. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Yeah it' s all javascript. However, most of what it is has nothing to do with code. Its for the beginner who doesn't know how to code. It's mostly 'do this, this and this'. So basic and simple. I liked 'unity in action' as an intermediate book if you know anything about coding.

    Hey eric, is there a way that the pac-man stuff could be translated to c#? I posted most of the changes already, but you use delegates and stuff which I am not familiar with. I am not sure what they are or why you use them. Couldn't just calling a function work just as well?

    Or would it be possible for you to do a video or something? This would help your sales to. I was thinking of 1) start up stuff, then 2) This is how to move, 3) this is how to check for colliders, 4) this is how to trigger stuff. I did go though the gem demo but giving a ton of code doesn't really help. I have figurered out the graphics and did 3 Ms. Pac-Man mazes and pac-man. these were done differently as I learned how best to do the graphics. I am now ready for the api. So I was going to ask this anyways in your tile sprite area, but this pac-man tutorial seems like it would be good to do and included in the plug-in. (Actually, gauntlet would probably be better as it has projectiles and all). If not, then could you just help me with 1) how to move then separately, 2) how to detect colliders before moving, 3) separately how to detect a trigger and do something.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No; you should look up delegates in C# since it's the same thing in both languages (using delegates from Unityscript in C# will work, and vice versa).

    1) I'm not sure what you're referring to? 2) Use GetCollider with the current position plus the desired direction, as shown in the pacman code. 3) Use GetTrigger with the position. The demos included with SpriteTile show these things too (e.g. TriggerDemo).

    --Eric
     
  34. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Eric, so let me try this another way. I have the pac-man maze done and pac-man character, ghosts and fruits. So now it's time to program. Hoes does one get it to display the map?

    Let's start with step 1. On the 'maingamecontrol' game object I have the following code. It is in c# and does not display the pac-man map. I have the maze and camera both attached in the inspecter. It gives an error listed below.

    Code (CSharp):
    1. /////////////////////////////////////////////////////////////////////////////////////////////////////
    2.     using UnityEngine;
    3.     using System.Collections;
    4.     using SpriteTile;
    5.  
    6. /////////////////////////////////////////////////////////////////////////////////////////////////////
    7. public class MainGameControl : MonoBehaviour
    8. {
    9.     /////////////////////////////////////////////////////////////////////////////////////////////////////
    10.     //VARIABLES
    11.         public Camera tileCam;
    12.         public TextAsset myLevel;
    13.  
    14.         int currentScore = 0;
    15.         int highScore = 0;
    16.     /////////////////////////////////////////////////////////////////////////////////////////////////////
    17.  
    18.     /////////////////////////////////////////////////////////////////////////////////////////////////////
    19.     void Awake ()
    20.     {
    21.         Tile.SetCamera(tileCam);
    22.         Tile.LoadLevel(myLevel);
    23.         Cursor.visible = false;
    24.     }
    25.     /////////////////////////////////////////////////////////////////////////////////////////////////////



    Error:
    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    SpriteTile.Tile.InitializeSprites ()
    SpriteTile.Tile.SetCamera (UnityEngine.Camera[] cameras)
    SpriteTile.Tile.SetCamera (UnityEngine.Camera camera)
    MainGameControl.Awake () (at Assets/Morphing Pac-Man/Scripts/MainGameControl.cs:22)
     

    Attached Files:

  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I tried your script with the pacman project posted here and it works fine. Do you have any other scripts that might be interfering somehow? You can send me the project (via PM, don't post it here) and I'll take a look.

    --Eric
     
  36. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    I'll PM you with the project, however there is nothing else in it except for this script.
     
  37. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    OK, so I am trying this out again. How would you move pac-man from 1 tile to the next? If one used colliders, then pac-man would get off. So what I really want to do is keep pac-man on the path and not stay from it. So using unity with supertilemap I do have a maze. I am trying to figure out how to keep him on the path. Each dot area can be a trigger to tell pac-man which direction he can go an all. However, how do you keep him just on the path? Do you use a moveto command? So he gets to an intersection, the invisible object says he can go in 1 of 4 directions. The joystick is pointing up but now it's right. How do you keep him just on the path>

    Seems easy enough and I know there are some old school programmers here that loved the tile based games.
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Basically lerp from one position to the next. The map is an array, no physics used.

    --Eric
     
    Kiwasi likes this.
  39. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    So if at cords 1x1 moving right to 2x1, then just lerp to 2x1? Not sure how to do that. here is what I go so far. I'm not really doing a pac-man game but am using this to learn tiles. This moves pac-man in the 4 directions. there are no checks for wall and he can change direction any where (even if not on the path).

    Code (CSharp):
    1. /////////////////////////////////////////////////////////////
    2.     using UnityEngine;
    3.     using System.Collections;
    4.  
    5. /////////////////////////////////////////////////////////////
    6. public class CharacterControl : MonoBehaviour
    7. {
    8.     //VARIABLES
    9.         public float x_Poistion = 14.5f;
    10.         public float y_Position = 7.5f;
    11.         public float speed = 6;
    12.  
    13.         int lastDirection = 1;          //1=right, 2=down, 3=left, 4=up
    14.         Animator ani;
    15.  
    16.     /////////////////////////////////////////////////
    17.     private void Start()
    18.     {
    19.         ani = GetComponent<Animator>();
    20.     }
    21.  
    22.     /////////////////////////////////////////////////
    23.     void Update()
    24.     {
    25.         ///////////////
    26.         if (Input.GetKey(KeyCode.UpArrow))
    27.         {
    28.             transform.Translate(Vector2.up * Time.deltaTime * speed);
    29.             ani.Play("Up");
    30.             lastDirection = 4;                                                  //Has president over other directions when moving.  So 4, 2, 3, 1.
    31.         }
    32.         ///////////////
    33.         else if (Input.GetKey(KeyCode.DownArrow))
    34.         {
    35.             transform.Translate(Vector2.down * Time.deltaTime * speed);
    36.             ani.Play("Down");
    37.             lastDirection = 2;
    38.         }
    39.         ///////////////
    40.         else if (Input.GetKey(KeyCode.LeftArrow))
    41.         {
    42.             transform.Translate(Vector2.left * Time.deltaTime * speed);
    43.             ani.Play("Left");
    44.             lastDirection = 3;
    45.         }
    46.         ///////////////
    47.         else if (Input.GetKey(KeyCode.RightArrow))
    48.         {
    49.             transform.Translate(Vector2.right * Time.deltaTime * speed);
    50.             ani.Play("Right");
    51.             lastDirection = 1;
    52.         }    
    53.         ///////////////
    54.         else
    55.         {
    56.             if (lastDirection == 1)
    57.             {
    58.                 transform.Translate(Vector2.right * Time.deltaTime * speed);
    59.                 ani.Play("Right");
    60.             }
    61.             else if (lastDirection == 2)
    62.             {
    63.                 transform.Translate(Vector2.down * Time.deltaTime * speed);
    64.                 ani.Play("Down");
    65.             }
    66.             else if (lastDirection == 3)
    67.             {
    68.                 transform.Translate(Vector2.left * Time.deltaTime * speed);
    69.                 ani.Play("Left");
    70.             }
    71.             else if (lastDirection == 4)
    72.             {
    73.                 transform.Translate(Vector2.up * Time.deltaTime * speed);
    74.                 ani.Play("Up");
    75.             }
    76.             else
    77.             {
    78.                 //Error. There has to be a last direction.
    79.             }
    80.         }
    81.         ///////////////
    82.     }
    83.     /////////////////////////////////////////////////////////////
    84. }
    85.  
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    transform.Translate moves a specific relative distance. Probably easiest to use transform.position in a coroutine.

    --Eric
     
  41. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Could you give me an example? I know what a coroutine is but how to do it?

    Let's say pac-man is on a 10x10 grid and he is currently at 5,5. So he wants to go right to 6,5. How would this be coded?
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  43. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
  44. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    So I have pac-man moving around the maze but I am using colliders which sucks. Pac-Man doesn't go in 90 degree turns. I am using a coroutine like suggested so he does move fine. Thanks. This is how they are moving in the title screen (not the gameplay yet). So the movement is in a coroutine from fixed positions. The while loop takes into account the rounding errors. It'll be off by .000001 and thus never gets to the position. This fixes that on either side of the target position. So this the title screen where pac-man is chased by the ghosts, eats the power ill, reverses direction and chases the ghosts.
    Code (CSharp):
    1.     /////////////////////////////////////////////////
    2.     IEnumerator MoveOverSpeed (GameObject gameObject_B, Vector2 pos_B, float speed_B)
    3.     {
    4.         // Move to pos_V2 power pill.
    5.          
    6.             while (gameObject_B.transform.position.x > pos_B.x + treshold_FLOAT || gameObject_B.transform.position.x < pos_B.x - treshold_FLOAT)
    7.             {
    8.                 gameObject_B.transform.position = Vector2.MoveTowards(gameObject_B.transform.position, pos_B, speed_B * Time.deltaTime);
    9.  
    10.                 redGhost_GO.transform.position = Vector2.MoveTowards(redGhost_GO.transform.position, pos_B, speed_Ghosts_Chase_FLOAT * Time.deltaTime);
    11.                 pinkGhost_GO.transform.position = Vector2.MoveTowards(pinkGhost_GO.transform.position, pos_B, speed_Ghosts_Chase_FLOAT * Time.deltaTime);
    12.                 blueGhost_GO.transform.position = Vector2.MoveTowards(blueGhost_GO.transform.position, pos_B, speed_Ghosts_Chase_FLOAT * Time.deltaTime);
    13.                 goldGhost_GO.transform.position = Vector2.MoveTowards(goldGhost_GO.transform.position, pos_B, speed_Ghosts_Chase_FLOAT * Time.deltaTime);
    14.  
    15.                 yield return new WaitForEndOfFrame ();
    16.             }
    17.                 gameObject_B.transform.position = pos_B;
    18.  
    19.             powerPill_GO.SetActive(false);
    20.             isCoroutineDoneYet_1 = true;
    21.     }
    22.  
    23.     /////////////////////////////////////////////////

    Now getting back to the arrays. I have never been good at them. I was wondering if someone could explain that in code. I guess we need a 3d array? The first and second numbers would be the x and y position. The third would be a 0 or 1 indicating if the path was open or had a wall (or basically a 0 indicated a path. Anything else would not be able to be traveled). I've read a number of messages on different ways to do it but nothing definitive. I would like to do this in c# to learn. What would be really cool is someone showing this in a 3x3 grid.
     
    Last edited: May 26, 2018
  45. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I would use a 2D array, and bundle up everything else you need into a struct that goes in the array.
     
  46. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Great. Thanks.....I have no idea what you are talking about sorry.
     
  47. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    So take the terms one at a time and google them.
     
  48. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    Kiwasi, Why are you trying to start a flame war? Either help or STFU.

    I have googled them. I have watched videos. I have read about them. This is why I'm asking questions here. It's confusing. There are a lot of really cool people here and I thank them for their help. I just don't get the referencing part. For everyone else that has answered, thank you. This is what forems are meant for.
     
  49. MadMaximus

    MadMaximus

    Joined:
    Jan 25, 2016
    Posts:
    5
    Replying to an old thread, I went with a node based 2d system. and using the moveTowards over specific time, it contained the movable rules for movement and made shure every object/player moves at the same speed until they interact with a new node. No collisions to check, just nodes you can move to next if your rule is you cannot move backwards. Every node just contained every direction that connected to another node, either up, down or left or right.

    Also every node had a bool to state if it was an intersection which had multiple move directions possible. Nodes not moveable also had a bool to state that, which ended with a group of useless non moveable data, but it was needed to
    add A* pathfinding. And the non movable data was like 512 bytes... maybe less.. I dunno.....

    Any ghost or even the player can plot a path using an A* algorithm to any point on the walkable map at choice or
    pick random places to end up. When either arrives at a node, then pick a new path, or if you control the player then
    pick any direction you want, it makes no difference at or between nodes.

    AI enemys willl never walk though walls, and the player you control cannot also. No wall collision to check other than
    running into an emeny. And the player can move freely in the map also.

    BUT!!! the title of this thread is

    "How would you do pac-man?????"

    So I would try a re-imagning.
    What if the PacMan was the enemy, just running through the streets of a small town eating ghosts and placing ghost trophy souls along the streets...

    you as a GHOST now need to free your fellow trapped souls and return them to a set place to get some rest. Pick them up, and return them to a spot to gain points.

    Reving an old project,