- Home /
2D Grid Movement (turn based)
I trying to create a Turn Based Strategy behaviour where you move a gameObject from 1 tile of a grid to another tile near it
I have created the Grid using sprites as gameObjects but can't sort out the movement part, I can move tile to tile continuously with mouseClick or w,a,s,d but want to implement the "player can move only x tiles a turn" thing, found in many TBS games
My current setup is like this
Without seeing any of your code, i can just state the obvious. You must make a counter that counts down or up as you make a move and make a condition so that when that number reaches a certain value, you can't move anymore.
How do you move from one tile to another?
Can you put a count in relation to this tile to tile movement code that limits total movement(how many times this code is executed)?
@$$anonymous$$rSoad and @Nose$$anonymous$$ills thanks for your comments but I actually solved it, I created this question almost 12 hours ago, which took 3-4 hours to get approved and by that time by hit and trials, I finally found a method. Added some points as a answer to what I did.
Answer by shubhank008 · Dec 20, 2014 at 06:35 AM
To anyone in same situation as me, here is how I solved both my problems.
Added Colliders to my charGO and tileGO around it.
Created triggerCollider on player to get the tileGO player is standing on, added some conditional statements.
Using the above tileGO, used Physics2D.OverlapCircleAll (+-1 x/y tileGO) to get the Colliders from each direction of tileGO
Using each Collider, got the GO of the tiles from all direction. Changed their sprite to a different colored sprite to "visualize" walkable path
Used coroutine, lerp and basic method to detect mouse click on a tile and move player from tileGO to clickedTileGO
Again, this was for a prototype to test out if I can do what I have in mind, once all is done, I will start cleaning the code and workarounds I used, create proper sprites, animations, etc. but this should give you some insight on how you can do it
Answer by Lancemaker_ · Jan 16, 2015 at 12:42 AM
a*pathfinding can solve that. i cant program it, but there are lots of tutorials online, its easyer on 2d i think.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174439im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Question about tactics movement 0 Answers
Grid based movement collision detection 1 Answer
Best way to implement a grid system 1 Answer
Best approach to generating a grid for basic A* pathfinding 1 Answer