- Home /
Civ Like Game Handling Tile Interactions
I've been planning out a civ like strategy game which would uses hexes or tiles. For this type of game it seems to me that colliders are not really necessary since all movement and unit placement is handled by the game.
I'm looking for some guidance regarding how to handle checking for interactions between tiles and units. I understand this is pretty heavily dependent on how the game is set up and structured but if anyone can provide me with any tips or suggestions on approaching how to design it it'd be a tremendous help.
The way I've considered handling it would be just merely writing a method to check the unit's or tile's status and initiate combat or display the appropriate options depending on the type of tile/whether it's occupied/etc. One of the issues I for see in this approach is that it would lead a very large if-else tree or a large switch statement and I'm not sure how this will affect performance.
Any input would be appreciated!
Answer by hexagonius · Jun 29, 2018 at 07:34 PM
First of all a link to hexmaps:
Catlike coding hexmap tutorial
For the second part, thinking about large if else statements is already not the best approach. The first approach, thinking about the map as the representation (view) of the game state and logic (model), is a good idea. Check out the Mode-View-Controller pattern to get an idea how to keep visuals seperate from logic.
A little guidance example:
Think about unit selection of a tile. Since mouse input must be polled and in that be triggered by Unity callbacks, you'd need a MonoBehaviour as your InputManager. This Manager can direction these clicks to another class that is aware of all the tiles. It could then, since it is a hexmap, calculate which you clicked and return it. The result could then be passed into another class that knows the internals of a tile, like if there are units, gold, whatever. Here comes the tricky part with the if else. Depending on possibilities, there could just be an object reference to some occupant (gold, unit, building). if that is not null, you can then pass it depending on it's actual type to whatever class will handle it. So it's less if gold if unit if... but is it occupied, give me the occupant, otherwise do nothing (or pick this field as a destination for yet another class responsible for pathfinding if you have previously selected a unit to walk).
I could go on, but maybe that's giving you the right idea.
Quill18 has a veeeeerry long Tutorial where he explains very well how a MVP works and shows that while building a base building game, also using A* Pathfinding:
Quill18 Base Building Game Tutorial
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Strategy Pattern with Monobehaviours 2 Answers
Colliding without gravity 2 Answers
Collider doesn't work always 1 Answer
Overcoming Mesh Colliders (car falls through street) 1 Answer