Let me start by saying that I’m fairly new to Unity and programming in general. I’m currently teaching myself C# and I’ve been going through the tutorials, the forums and several other resources. This is my first post and I plan to get involved in the community. I’m very passionate about game design and though I’m just starting out, I’m dedicated to learning and making this a second home.
I have a game that began as a board game roughly a decade ago and I have been trying to convert it into a digital format.
The game has movement similar to chess regarding the grid based movement and restricted movement patterns. I plan to keep the mechanic of one hit kills and add mechanics such as ranged attacks and abilities that alter attack and movement patterns and styles.
I realize that this is a big task to tackle and I’ve got a ways to go, but I’ve decided to start small and see if I can figure out some of the basic mechanics. I’ve been at this for a little while and I understand the basics of programming. I’m familiar with variables, loops, operators, classes, functions. I understand how to move objects, destroy objects, fire projectiles, keep scores and a few other tidbits. I’m just a little fuzzy on the best approach to handling the board and movement. I’ve done some research, though, and this is what I’ve found:
The best way to handle grid based strategy is to build a grid using an array, and use raycasting to determine each piece’s location. Then I understand that there is an algorithm for determining legal moves.
You can use the projector to draw grid lines. There is also a way to illuminate a tile with the projector by projecting a texture, I believe it has something to do with ‘SetPixel’ or something similar.
Here are some of the problems I’m facing, the solutions I’ve considered and the questions I have:
Problems:
I respect the idea of drawing a grid but the majority of my playing fields are not going to be uniform. I won’t have a 10x10 or a 12x12 grid. It will be more of an odd shape made of tiles.
Also, if I were to go with the approach of creating an array of tiles, I vaguely understand how you can assign a unit to a location in the array but I’m totally lost as to the algorithm for determining where the piece can move to.
Approaches:
I’ve thought of just making the tiles individually and using colliders to determine whether or not the space is occupied or if it can be moved to. You would click on the unit and it would send out raycasts in the directions the unit can move and the colliders would return whether or not a space exists, if it is occupied and then give you movement options. The tiles would detect whether or not they’d been hit by a Raycast and if they weren’t occupied, they would become clickable and the unit would move to their transform. If an enemy piece were on the space, when the player’s unit hit the enemy piece, it would destroy it.
I really like the idea of using raycasts but 1. I can’t help but wonder if there is something I’m not understanding about the array approach that might solve my problem and 2. I have certain movements that skip spaces or make turns(similar to a knight in chess) and I’m not sure how I’d fire a raycast from a new location or make the original turn.
I’ve also considered instantiating space checker objects at the appropriate locations in relation to the unit and if the space checker finds a space that is able to be moved to, it would become clickable and so on. With this approach, though, I’m worried that the massive amount of game objects might slow down the game or become hard to sort through and organize.
I’ve looked up videos on grid based movement and turn based strategy but the majority of games rely on a range of spaces as opposed to a specific movement like chess.
Questions:
When drawing an array, could I make it so certain tiles weren’t drawn and couldn’t be moved to, if so how?
Once a ray is cast to determine whether or not there is an available space to be moved to, is there a way to flip a bool on the space that’s been hit by the raycast?
I could make the spaces black and white as in chess in regards to the units that skip spaces, but how would I go about making a piece move like a knight in chess?
Lastly, am I going about this the right way or is there something I’m missing?
I realize this post is pretty lengthy and I do apologize.
I don’t expect to be handed code and I certainly don’t want the work done for me. I’m looking to learn as I want this to be a growing experience. I realize I’ve got a lot of challenges ahead of me but I’m in this for the long haul.
If someone could give me some advice, refer me to some tutorials I may have missed or just point me in the right direction, I would be most appreciative.
Also, if I’ve formatted this post incorrectly, I’m open to criticism on how I can better request assistance in the future. I appreciate anyone who has taken the time to read this.
Thank you.