/// <summary> /// Generates a new path for the player based on the path provided /// If it is a new round then all AI car paths will be reset too /// </summary> /// <param name="path">List of all node IDs for the player to use as a path</param> /// <param name="newRound">Boolean indicating whether the path is being made for a new round</param> /// <param name="newCurrentNode">Integer indicating which is the next current node (used for changing existing paths)</param> public void makePath(List <string> path, bool newRound = true, int newCurrentNode = 0) { // Generate Node Elements for path GameObject NodeGameObject = PathGameObject.transform.GetChild(0).gameObject; bool isFirst = true; Vector3 nodePos; foreach (string nodeID in path) { Graph.Node node = g.nodeIdNodeDict[nodeID]; Vector2d xy = world.toXY(node.lat, node.lon); nodePos = new Vector3((float)xy[0], 0.71f, (float)xy[1]); if (isFirst) { NodeGameObject.transform.position = (nodePos); isFirst = false; } else { GameObject childObject = Instantiate(NodeGameObject) as GameObject; childObject.transform.position = (nodePos); childObject.transform.SetParent(PathGameObject.transform); } } av = GetComponentInChildren <AVController>(); av.setPath(path); av.currentNode = newCurrentNode; av.resetPaths(newRound); av.setOneWayRoads(path); }
/// <summary> /// Sets the path for the car gameobject and places it in the world /// </summary> /// <param name="CarObject">GameObject representing the AI car</param> /// <param name="path">List of nodes for the car to travel to which form a path</param> /// <param name="dumbCarID">Integer identifying the car</param> /// <param name="smart">Boolean indicating whether the car is smart or not</param> private void setAICarParams(GameObject CarObject, List <string> path, int dumbCarID, bool smart) { // Make path from start to end GameObject PathGameObject = CarObject.transform.Find("Path").gameObject; if (!useCachedPath) { //Path thisPath = new Path() { nodeIDs = path }; DumbCar thisCar = new DumbCar(); thisCar.id = dumbCarID; //thisCar.path = path.ToArray(); dumbCars.Add(thisCar); // NOTE: seems to add all cars whether they are dumb or not //paths.Add(thisPath); } makePath(PathGameObject, g, path); AVController av = CarObject.GetComponentInChildren <AVController>(); Vector3 offset = av.setOneWayRoads(path); av.setPath(path); av.isSmart = smart; // Set spawn GameObject SpawnObject = CarObject.transform.Find("Spawn").gameObject; GameObject SpawnPointObject = SpawnObject.transform.Find("SpawnPoint").gameObject; Graph.Node startingNode = g.nodeIdNodeDict[path[0]]; Vector2d xy = world.toXY(startingNode.lat, startingNode.lon); if (smart) { av.roundOver = false; av.TP2Start(); } //SpawnPointObject.transform.position = new Vector3((float)xy[0], 0.71f, (float)xy[1]) + transform.InverseTransformPoint(offset); }
private void setAICarParams(GameObject CarObject, List <string> path, int dumbCarID) { // Make path from start to end GameObject PathGameObject = CarObject.transform.Find("Path").gameObject; if (!useCachedPath) { //Path thisPath = new Path() { nodeIDs = path }; DumbCar thisCar = new DumbCar(); thisCar.id = dumbCarID; thisCar.path = path.ToArray(); dumbCars.Add(thisCar); //paths.Add(thisPath); } makePath(PathGameObject, g, path); AVController av = CarObject.GetComponentInChildren <AVController>(); Vector3 offset = av.setOneWayRoads(path); av.setPath(path); // Set spawn GameObject SpawnObject = CarObject.transform.Find("Spawn").gameObject; GameObject SpawnPointObject = SpawnObject.transform.Find("SpawnPoint").gameObject; Graph.Node startingNode = g.nodeIdNodeDict[path[0]]; UnityEngine.Debug.Log("StartingNode nodeId: " + startingNode.nodeId); UnityEngine.Debug.Log("StartingNode Lat: " + startingNode.lat); UnityEngine.Debug.Log("StartingNode Lon: " + startingNode.lon); Vector2d xy = world.toXY(startingNode.lat, startingNode.lon); UnityEngine.Debug.Log("X: " + xy[0]); UnityEngine.Debug.Log("Y: " + xy[1]); //SpawnPointObject.transform.position = new Vector3((float)xy[0], 0.71f, (float)xy[1]) + transform.InverseTransformPoint(offset); }