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() { if (Input.GetMouseButtonDown(0)) { bool false_alarm = false; Vector3 mouse_pos = Input.mousePosition; if (mouse_pos.x < 0 || mouse_pos.y < 0 || mouse_pos.x > Screen.width || mouse_pos.y > Screen.height) { false_alarm = true; } if (!false_alarm) { clicked = cursorOnTransform; TileNode tn = QuantizeLocalize.Quantize(clicked, tg); goal_script.setGoal(tn); } } }
public SteerFabulaClip(JSONNode json, TimelineAsset p_timeline, PlayableDirector p_director) : base(json, p_timeline, p_director) { ending_location = GameObject.Find(json["end_pos_name"].Value); // Quantize to find start and finish nodes startNode = QuantizeLocalize.Quantize(starting_location.transform.position, TrackAttributes.TG); goalNode = QuantizeLocalize.Quantize(ending_location.transform.position, TrackAttributes.TG); // Calculate path Path = PathFind.Dijkstra(TrackAttributes.TG, startNode, goalNode); // create Lerp for each edge in path var eachSeg = duration / Path.Count; int n = 0; var lastNode = startNode; foreach (Node p in Path) { ClipInfo CI = new ClipInfo(p_director, start + n * eachSeg, eachSeg, Name); CI.SimpleLerpClip(agent, lastNode.transform, p.transform); lastNode = p; n++; } // run animation across whole thing if not null if (json["animation_name"] != null) { control_track_clip = ctrack.CreateDefaultClip(); control_track_clip.start = start + 0.06f; control_track_clip.duration = duration - 0.06f; control_track_clip.displayName = Name; controlAnim = control_track_clip.asset as ControlPlayableAsset; AnimateBind(controlAnim, animTimelineObject); } }
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); }