Chess Game in Unity Tutorial! Part 2: Piece Movement and Input System.

In this part of the chess series, we will make our chess pieces move and react to the input. Let’s begin!

——Project on Github——

——UML Diagram——-

——Assets——

Low Poly Chess Pack:

Wooden Floor Materials:

Table with chairs x3 Free:

22 Comments

  1. Please change in chessplayer class method name to: public void GenerateAllPossibleMoves()
    {
    foreach (var piece in activePieces)
    {
    if (board.HasPiece(piece))
    piece.SelectAvaliableSquares(); // Change from SelectAvailableSquares to SelectAvaliableSquares

    }
    }

  2. Does anyone know how I would use this with the newer Input System Package?As other assets I'm using virtually prevent me from using Active Input handling

  3. plz make a video about how to make a city map in unity

  4. Are you planning to upload more content? Your channel seems to have really relevant content for game development in Unity.

  5. I have gone through every script and I can not figure out what is wrong, I can't select a piece. Even with the debug input handler it says i am clicking on null, I have tripple checked the code and even used your scripts from the github, am I forgetting to add a component to something maybe? I know it is hard to solve this without looking at my project but any insight would be appretiated

  6. its very hard for first time. this is the very first tutorial I learn. took me 50 minute to finish this one|

    why king use knight? why don't use queen

  7. @16:00 I was trying to rotate the white pieces to face the correct way by adding a SetOrientation method in Piece.cs. It made all the pieces face in crazy directions, and it was upsetting my entire understanding about how prefabs/gameObjects/scripts should work. This little bug was the cause of that. Faith in Unity restored.

  8. When do you explain how the pieces are destroyed when a piece captures another?

  9. Watch vid in 0.75x speed. Easier to follow along, trust me.

    Also makes music sound a little bit more like Minecraft cave music…

  10. 4:30 ay, you can also add an OnPointerDown() event trigger, much quicker 🙂
    Also, it works for both mobile and PC

  11. What the fun? I set my board size to 8, but my top-right square is returning 13,13, and my bottom left is -6,-6??

  12. Hey! So I left a comment on the last video about how Iobjecttweener said it needed to be abstract. I sorta fixed that by just replacing all references to iobjecttweener to instanttweener instead.

    Now the issue is I can't click on the pieces. The pieces can be selected but very unpredictably and by clicking on different areas where the pieces are not. Like off the board in the top left to select a middle of the board on the bottom piece. Then the little green/red selector is in the wrong spot. I can see that your code works and I followed you exactly, even replacing my code with yours from github a couple of times. Could it be the version of unity that is the problem?

    Thank you!

    Edit: Maybe there's a package I'm missing or something? I updated your project files to the newest version of Unity and it still seems to work fine, but when I copy all your existing stuff into my project it doesn't?

  13. If your pieces dont show selector try this code: int x = Mathf.FloorToInt((inputPosition).x / squareSize) + BOARD_SIZE / 2;

    int y = Mathf.FloorToInt((inputPosition).z / squareSize) + BOARD_SIZE / 2; in Board class

  14. inputHandlers = GetComponents<IInputHandler>();

    This line from the input receiver abstract class give me an error. And I think it's something to do with the array. Someone, pls help!!

  15. Very nice video. One small improvement I would suggest: Instead of handling the active player automatically, the board layout should return the "ActivePlayer". This would allow for various other improvements down the line, like challenges, where you get a pre defined board with information about who the next player is.
    BoardLayout could also be populated by a FEN string later on.

  16. For those who cannot move pieces, make sure to turn on mesh collider for your renderer for your board. Secondly replace all uses of IObjectTweener with InstantTweener Instead. One more thing, when making your square selector, make another 3d object in it so that you can select which square you want a piece to go to. Hope this helped. This took a long time to figure out.

  17. i know it is late but i hava a issue with the coords generating. at the game start all pieces doesnt have available moves, the list is empty, when i create a move in the list i can move the piece but it doesnt generate them automatically. hope someone can help me, i am creating the code like the tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *