Quantcast
Channel: Questions in topic: "endless"
Viewing all articles
Browse latest Browse all 123

How to create endless board game path

$
0
0
So I'm making an endless RPG type board game, but I'm having trouble with setting the route for player to move. On "Start" function I instantiate custom amount of "Road" prefabs ("Road" is a 10x10 green shape which has custom "road cut out" filled with 1x1 brown road tiles), which have different directions. When these prefabs are instantiated I parent them to the GameObject that has Route script attached to it and put only brown tiles into a list that makes up the road. Then using OnDrawGizmos I pick every single tile and try to plot the road with green line, but in the picture it's clear that green line is all messed up and doesn't follow a path (By the way the start is bottom right). In list I can see that tiles are put in random order, but I can't seem to figure out how to sort or put them in a list so that they create a normal path. ![alt text][1] [1]: /storage/temp/176817-start.jpg public class Route : MonoBehaviour { GameObject[] childObjects; public List nodeList = new List(); private void OnDrawGizmos() { Gizmos.color = Color.green; FillNodes(); for (int i = 0; i < nodeList.Count; i++) { Vector3 currentPos = nodeList[i].position; if(i > 0) { Vector3 prevPos = nodeList[i - 1].position; Gizmos.DrawLine(prevPos, currentPos); } } } void FillNodes() { nodeList.Clear(); childObjects = GameObject.FindGameObjectsWithTag("Tile"); foreach (GameObject child in childObjects) { if(child != transform) { nodeList.Add(child.transform); } } } }

Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>