public void setGoal(TileNode tn) { tileGoal = tn; goalObject = tn.gameObject; if (previousGoal != null) { previousGoal.GetComponent <Renderer>().material = non_goal_material; } previousGoal = goalObject; goalObject.GetComponent <Renderer>().material = goal_material; goalPosition = QuantizeLocalize.Localize(tn); }
void Update() { currentGoalTile = goalComponent.getGoalTile(); currentTile = QuantizeLocalize.Quantize(transform.position, tg); if (prevGoalTile != currentGoalTile) { foreach (TileNode tn in currentPath) { if (tn.isEqual(currentTile)) { continue; } tn.setOffMaterial(); } currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); prevGoalTile = currentGoalTile; // light up all tiles foreach (TileNode tn in currentPath) { if (tn.isEqual(currentGoalTile)) { continue; } tn.setPlanMaterial(); } currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); } // determine how to set force if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); // pop when seek says we've made it into range and seek the next target if (seek.changeGoal) { nextTile = currentPath.Pop(); nextTile.setNextMaterial(); currentGoal = QuantizeLocalize.Localize(nextTile); if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); } else { ds_force = arrive.getSteering(currentGoal); } } } else if (currentPath.Count == 0) { ds_force = arrive.getSteering(currentGoal); } ds_torque = align.getSteering(currentGoal); ds = new DynoSteering(); ds.force = ds_force.force; ds.torque = ds_torque.torque; kso = char_RigidBody.updateSteering(ds, Time.deltaTime); transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z); transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f); }
void Update() { // check what the current goal is currentGoalTile = goalComponent.tileGoal; // check if we are at the goal position currentTile = QuantizeLocalize.Quantize(transform.position, tg); // if we're at the goal position, then pick a new goal if (currentTile == currentGoalTile) { Debug.Log("here"); goalSetter.SetNextGoal(); currentGoalTile = goalComponent.tileGoal; // find path to new goal currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); // pick next point to seek currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); } else if (!hasPath) { currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile); currentGoal = QuantizeLocalize.Localize(currentPath.Pop()); hasPath = true; } // if we are not at last point on path if (currentPath.Count > 0) { // seek next point on path ds_force = seek.getSteering(currentGoal); // pop when seek says we've made it into range and seek the next target if (seek.changeGoal) { nextTile = currentPath.Pop(); currentGoal = QuantizeLocalize.Localize(nextTile); if (currentPath.Count > 0) { ds_force = seek.getSteering(currentGoal); } else { ds_force = arrive.getSteering(currentGoal); } } } // otherwise, we are approaching the path goal. we should arrive. else if (currentPath.Count == 0) { ds_force = arrive.getSteering(currentGoal); } ds_torque = align.getSteering(currentGoal); ds = new DynoSteering(); ds.force = ds_force.force; ds.torque = ds_torque.torque; kso = char_RigidBody.updateSteering(ds, Time.deltaTime); transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z); transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f); }
public void setGoal(Node tn) { tileGoal = tn; goalPosition = QuantizeLocalize.Localize(tn); }