private float getDistance(FollowOrb Orb1, FollowOrb Orb2) { Vector3 Orb1Pos = Orb1.gameObject.transform.position; Vector3 Orb2Pos = Orb2.gameObject.transform.position; return(Mathf.Sqrt(Orb1Pos.x * Orb2Pos.x + Orb1Pos.y * Orb2Pos.y + Orb1Pos.z * Orb2Pos.z)); }
private static bool CheckForOrb(FollowOrb[] path, FollowOrb orbLookingFor) { for (int i = 0; i < path.Length; i++) { if (path[i] == orbLookingFor) { return(true); } } return(false); }
private static bool CheckForOrb(List <FollowOrb> path, FollowOrb orbLookingFor) { foreach (FollowOrb FO in path) { if (FO == orbLookingFor) { return(true); } } return(false); }
public static List <FollowOrb> determinePath(FollowOrb StartingOrb, FollowOrb DestinationOrb) { Queue <FollowOrb> frontier = new Queue <FollowOrb>(); frontier.Enqueue(StartingOrb); FollowOrb[] camefrom = new FollowOrb[50]; camefrom[DestinationOrb.value] = null; FollowOrb current = new FollowOrb(); while (frontier.Count > 0) { current = frontier.Dequeue(); if (current == DestinationOrb) { break; } foreach (FollowOrb FO in current.neighbours) { if (CheckForOrb(camefrom, current) == false) { frontier.Enqueue(FO); camefrom[FO.value] = current; } } } List <FollowOrb> path = new List <FollowOrb>(); while (current != StartingOrb) { path.Add(current); current = camefrom[current.value]; } path.Reverse(); return(path); }