Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private List<Vector3Int> GetRiverPath(Vector3Int start, Vector3Int end, System.Random random)
- {
- List<Vector3Int> path = new();
- Vector3Int current = start;
- path.Add(current);
- while (current != end)
- {
- Vector3Int remainingDistance = end - current;
- int k = Sign(remainingDistance.x);
- int l = Sign(remainingDistance.y);
- Vector3Int direction;
- if (k != 0 && l != 0)
- {
- Vector3Int[] directions = new Vector3Int[3] { new Vector3Int(k, 0),
- new Vector3Int(k, l), new Vector3Int(0, l) };
- direction = directions[random.Next(directions.Length)];
- }
- else
- {
- Vector3Int[] directions = new Vector3Int[3] { new Vector3Int(k + l, k + l),
- new Vector3Int (k, l), new Vector3Int(k - l, l - k)};
- foreach (var dir in directions)
- {
- if (path.Contains(current + dir))
- {
- path.Remove(dir);
- }
- }
- direction = directions[random.Next(directions.Length)];
- }
- current += direction;
- path.Add(current);
- }
- return path;
- }
Add Comment
Please, Sign In to add comment