public void MoveTo(int grid_x, int grid_y) { // Get current point NavigationPoint curr_nav_point = navigation_entity.GetNavMap().GetClosestNavPoint(gameObject.transform.position).GetComponent <NavigationPoint>(); // Ask for path and check if the position is different to the actual if (navigation_entity.MoveTo(grid_x, grid_y)) { // Tell the tile that we are leaving //curr_nav_point.PlayerLeavesTile(gameObject); } // Get path //List<Vector3> path = navigation_entity.GetCurrentPath(); //// Avoid overlap //if (path.Count > 0) //{ // // Get last point // GameObject final_point = navigation_entity.GetNavMap().GetClosestNavPoint(path[0]); // NavigationPoint final_point_script = final_point.GetComponent<NavigationPoint>(); // // Change the last point to the correct tile position depending of how much players there are on it // Vector3 new_pos = final_point_script.AskForPlayerPosition(this.gameObject); // path[0] = new_pos; //} //else //{ // curr_nav_point.AskForPlayerPosition(this.gameObject); //} }
// Update is called once per frame void Update() { Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)), new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green); Debug.DrawLine(new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)), new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green); Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z - (tile_size / 2)), Color.green); Debug.DrawLine(new Vector3(transform.position.x + (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)), new Vector3(transform.position.x - (tile_size / 2), transform.position.y, transform.position.z + (tile_size / 2)), Color.green); List <GameObject> neig = GetNeighbours(); for (int i = 0; i < neig.Count; i++) { NavigationPoint np = neig[i].GetComponent <NavigationPoint>(); if (!np.IsNeighbour(gameObject)) { return; } Debug.DrawLine(new Vector3(transform.position.x, transform.position.y, transform.position.z), new Vector3(neig[i].transform.position.x, neig[i].transform.position.y, neig[i].transform.position.z), Color.red); } }
void Start() { // Get map points for (int i = 0; i < nav_map_points_parent.transform.childCount; i++) { GameObject current_point_go = nav_map_points_parent.transform.GetChild(i).gameObject; NavigationPoint np = current_point_go.GetComponent <NavigationPoint>(); np.nav_map = this; List <GameObject> nb = np.GetNeighbours(); for (int y = 0; y < nb.Count; y++) { NavigationPoint npn = nb[y].GetComponent <NavigationPoint>(); if (!npn.IsNeighbour(current_point_go)) { npn.AddBeighbour(current_point_go); } } points.Add(current_point_go); } grid = TransformMapToGrid(GetPoints(), size_x, size_y); }
public void DeletePoint(int index) { NavigationPoint point = navigationPoints[index]; GameObject.Destroy(point.pointObject); navigationPoints.RemoveAt(index); }
//for pointID=0 navigatios arrowwill be hidden public void showNavigationArrow(int pointID) { if (pointID >= 0 && navigationPoints[pointID] != null) { NavigationArrow.SetActive(true); NavigationDistanceText.gameObject.SetActive(true); activeNavigationPoint = navigationPoints[pointID]; //teď se probourat dovnitř a nastavit barvičky jednotlivých komponent NavigationArrow.transform.GetChild(0).Find("arrow").gameObject.GetComponent <Renderer>().material.color = activeNavigationPoint.color; NavigationArrow.transform.GetChild(0).Find("backside").gameObject.GetComponent <Renderer>().material.color = activeNavigationPoint.backsideColor; if (HomeArrow.activeSelf) { showBothArrows(); } else { showOneArrow(); } } else { NavigationArrow.SetActive(false); NavigationDistanceText.gameObject.SetActive(false); activeNavigationPoint = null; showOneArrow(); } }
private void DetermineAIState() { Collider[] detectedObjects = Physics.OverlapSphere(new Vector3(this.comShipMovement.gameObject.transform.position.x, this.comShipMovement.gameObject.transform.position.y, 0), this.sphereCastMagnitude, this.shipScanLayerMask); float totalSurroundingDangerScore = 0; foreach (Collider pointCollider in detectedObjects) { NavigationPoint currentNavPoint = pointCollider.gameObject.GetComponent <NavigationPoint>(); totalSurroundingDangerScore += currentNavPoint.dangerScore; } float averageSurroundingDangerScore = totalSurroundingDangerScore / (float)detectedObjects.Count(); if ((averageSurroundingDangerScore >= this.evadeTriggerThreshold) && (this.currentAIState != AIState.Evasive)) { this.currentAIState = AIState.Evasive; StartCoroutine(this.EvadeAttacks()); } else if ((averageSurroundingDangerScore < this.evadeTriggerThreshold) && (this.currentAIState != AIState.Attacking)) { this.currentAIState = AIState.Attacking; StartCoroutine(this.AttackPlayer()); } }
private async Task CheckTaxiProgress() { await PerformCheck(async() => { var closestPoint = _wayPoints.OrderBy(taxiPoint => taxiPoint.DistanceTo(_sender.Position.Coordinate)) .First(); // If this is true then we don't need to say the same commands again etc. if (_currentTaxiPoint == closestPoint) { return; } // We want to get rid of all the previous TaxiPoints in the list. We do this instead of just getting rid of the first in case // somehow the pilot manage to skip a TaxiPoint by going fast enough that they passed it before the check. var index = _wayPoints.IndexOf(_currentTaxiPoint); if (index > 1) { Logger.Trace($" {_sender.Id} skipped at least one taxi point"); } for (var i = _wayPoints.Count - 1; i >= 0; i--) { if (i > index) { continue; } Logger.Trace($"Removing {_wayPoints[i].Name} from route of {_sender.Id}"); _wayPoints.RemoveAt(i); } _currentTaxiPoint = closestPoint; Logger.Debug($"New closest TaxiPoint to {_sender.Id} is {_currentTaxiPoint.Name}"); if (_currentTaxiPoint is Runway) { // Check to see if we have any aircraft on initial or final if (_airfield.ControlledAircraft.Values.Any(x => _holdShortReasons.Contains(x.CurrentState) && x.Destination == _wayPoints.First())) { await SendMessage($"Hold short {_currentTaxiPoint.Name}"); await _atcState.FireAsync(Trigger.HoldShort); } else { if (_wayPoints.Count == 1) { await SendMessage($"Take-off {_currentTaxiPoint.Name} at your discretion"); await _atcState.FireAsync(Trigger.LineUpAndWait); } else { // If we have reached this bit in the code then the current taxi point is a runway that is not the terminus of the route // so tell the player they are good to cross. await SendMessage($"cross {_currentTaxiPoint.Name} at your discretion"); } } } }); }
public void AddPoint(Vector3 position, bool onGround) { Color col = colorArray[navigationPoints.Count % 8]; GameObject WayPointPointerPrefab; if (!onGround) { WayPointPointerPrefab = Resources.Load <GameObject>("Zones/WayPointPointer"); } else { WayPointPointerPrefab = Resources.Load <GameObject>("Zones/WayPointGroundPointer"); } GameObject WayPointPointer = Instantiate(WayPointPointerPrefab); WayPointPointer.transform.localPosition = position; WayPointPointer.transform.parent = transform; WayPointPointer.GetComponent <Renderer>().material.color = new Color(col.r, col.g, col.b, 0.5f); NavigationPoint point = new NavigationPoint(col, "Point " + PointCounter, onGround, WayPointPointer); PointCounter++; navigationPoints.Add(point); }
private float ComputeCost(NavigationPoint navPoint, NavigationAgent agent) { var addCost = additionalCost == null ? 0 : additionalCost.Invoke(agent, navPoint.position); var neighboursCost = _computeNeightboursCost ? GetNeightboursCost(navPoint) : 0; return((PointIsVisibleFromPlayerPosition(navPoint) ? VISIBLE_BY_PLAYER - addCost : addCost) + neighboursCost); }
/// <summary> /// Perform the next available Interaction. /// When no Interactions are available then busy gets set to false. /// </summary> private void PerformInteraction() { NavigationInteraction navigationInteraction = null; NavigationPoint navigationPoint = null; if (interactionQueue.Count > 0) { busy = true; navigationInteraction = interactionQueue[0]; navigationPoint = navigationInteraction.navigationPoint; } else { busy = false; return; } List <Vector2> route = new List <Vector2>(); if (currentPosition == navigationPoint.position) { route = new List <Vector2>() { currentPosition }; } else { Vector2 position = currentPosition; route = navigator.GetRoute(position, navigationPoint); } SetRoute(route, navigationInteraction); }
bool findSpawnPoint() { int checkptID = SvgManager.SvgData.currCheckpointID; NavigationPoint[] ntArray = FindObjectsOfType <NavigationPoint>(); foreach (NavigationPoint nt in ntArray) { if (nt.iD == checkptID) { mySpawnpoint = nt; break; } } //DEBUG if (mySpawnpoint == null) { Debug.LogErrorFormat("<color=red>ERROR: No entry point with ID " + checkptID + " was found in the current scene (" + SvgManager.SvgData.currentSceneName + ")</color>"); //DEBUG return(false); } //Executed only if we didn't return false just above return(true); }
public void TestDetermineNextPoint() { //Arrange var unitOfWork = new UnitOfWork(new DtsContext()); var droneOne = new Drone { CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B19C9EF8-3CF5-4A85-A0F7-4D516E9FD53C"))), TargetPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"))) }; var xPointOne = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneOne.CurrentPoint.XNeighbourId)); var zPointOne = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneOne.CurrentPoint.ZNeighbourId)); var droneTwo = new Drone { CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("EAFB1408-C53F-449D-9856-4B18BF32B861"))), TargetPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"))) }; var xPointTwo = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneTwo.CurrentPoint.XNeighbourId)); var zPointTwo = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneTwo.CurrentPoint.ZNeighbourId)); unitOfWork.Dispose(); //Act var resultOne = NavigationLogic.DetermineNextPoint(droneOne, xPointOne, zPointOne); var resultTwo = NavigationLogic.DetermineNextPoint(droneTwo, xPointTwo, zPointTwo); //Assert Assert.IsNotNull(resultOne, "A navigation point was not selected for result one"); Assert.AreEqual(xPointOne, resultOne, "The x coordinate was selected"); Assert.IsNotNull(resultTwo, "A navigation point was not selected for result two"); Assert.AreEqual(zPointTwo, resultTwo, "The z coordinate was selected"); }
//Calculate the Euclydian Distance between two points public static double CalculateDistance(NavigationPoint first, NavigationPoint second) { return (Math.Round(Math.Sqrt(Math.Pow(first.XPosition - second.XPosition, 2) + Math.Pow(first.YPosition - second.YPosition, 2) + Math.Pow(first.ZPosition - second.ZPosition, 2)), 2)); }
/// <summary> /// If Room is touched while a guest is selected and the room is available then the guest will be sent to the room and will be checked in. /// Else if the Bellhop is not null and the room should be cleaned then the room wil not be available to guests and the bellhop is sent over to clean it. /// Selected guest is always set to null if one was selected. /// </summary> /// <param name="collider">Collider of touched GameObject.</param> /// <param name="moneyHandler">Reference to the moneyHandler.</param> /// <param name="objectiveHandler">Reference to the objectiveHandler.</param> /// <param name="selectedGuest">Actual Reference to the selectedGuest in the TouchInput Script.</param> /// <param name="bellhop">Actual Reference to the bellhop in the TouchInput Script.</param> public override void TouchInteract(Collider2D collider, MoneyHandler moneyHandler, ObjectiveHandler objectiveHandler, ref Guest selectedGuest, ref Bellhop bellhop) { Room room = collider.GetComponent <Room>(); NavigationPoint navPoint = room.navigationPoint; if (selectedGuest & room.availableToGuests) { List <Vector2> route = selectedGuest.GetRoute(selectedGuest.currentPosition, navPoint); if (route != null) { selectedGuest.navigator.HighlightRooms(false); selectedGuest.SetRoute(route, room); selectedGuest.checkIn = false; selectedGuest.CheckIn(); moneyHandler.CheckIn(); room.DoorState(false); } } else if (bellhop) { if (room.shouldClean) { room.availableToGuests = false; bellhop.AddInteractionToQueue(room); } } if (selectedGuest) { selectedGuest.navigator.HighlightRooms(false); selectedGuest = null; } }
public async Task <RouteDirectionsResult> GetRouteDirections(NavigationPoint start, NavigationPoint end, NavigationMode navMode, int numRoutes = 3) { string travelMode; switch (navMode) { case NavigationMode.Drive: case NavigationMode.Rideshare: travelMode = "car"; break; case NavigationMode.Transit: travelMode = "bus"; break; default: travelMode = "car"; break; } var routeResult = await GetAzureResource("atlas", "route/directions/json", $"query={start.Latitude},{start.Longitude}:{end.Latitude},{end.Longitude}&traffic=true&routeType=fastest&maxAlternatives={numRoutes-1}&travelMode={travelMode}"); var resultContainer = await routeResult.Content.ReadAsAsync <RouteDirectionsResponse>(); Console.WriteLine(resultContainer.Routes.ToArray()); return(resultContainer.Routes[0]); }
private static ICurve CreateLabelAndBoundary(NavigationPoint navigationPoint, Microsoft.Msagl.Drawing.Node node) { node.Attr.LabelMargin *= 2; node.Label.IsVisible = false; var y = (navigationPoint.Latitude - airfield.Latitude) * 200000; var x = (navigationPoint.Longitude - airfield.Longitude) * 200000; var positionalPoint = new Microsoft.Msagl.Core.Geometry.Point(x, y); switch (navigationPoint) { case Runway _: node.Attr.Color = Color.Green; return(CurveFactory.CreateCircle(50, positionalPoint)); case Junction _: node.Attr.Shape = Shape.Hexagon; node.Attr.Color = Color.Blue; return(CurveFactory.CreateHexagon(100, 30, positionalPoint)); case ParkingSpot _: node.Attr.Color = Color.Orange; return(CurveFactory.CreateOctagon(100, 30, positionalPoint)); case WayPoint _: node.Attr.Color = Color.Purple; return(CurveFactory.CreateRectangle(100, 30, positionalPoint)); } return(CurveFactory.CreateCircle(5, positionalPoint)); }
public async Task<RoutingSegmentResult> GetCost(NavigationPoint start, NavigationPoint end, OptimizationParam optimizer) { // Call API from start to end to figure how much time it'll take var routingResult = await _mapsService.GetRouteDirections(start, end, NavigationMode); var routingCost = GetCostFromRouteSummary(routingResult.Summary, optimizer); return new RoutingSegmentResult(NavigationMode.ToString(), GetNavigationPointsFromLegs(routingResult.Legs), routingCost); }
void Update() { if (currentPoint.UpdateStateInput(transform, ref stateInput)) { currentPoint.ResetActions(); currentPoint = currentPoint.nextPoint; } }
void handleOnNavTrigger(NavigationPoint navTrigger) { //PC goes to exiting level if the navigation trigger is an exit if (navTrigger.isExit) { goExiting(); } }
public List <RoutingSegment> GetOptimalPath(NavigationPoint start, NavigationPoint end, AdjacencyGraph <NavigationPoint, WeightedEdge <NavigationPoint> > weightedGraph) { var shortestPathResult = weightedGraph.ShortestPathsBellmanFord(edge => edge.EdgeWeight, start); shortestPathResult(end, out var shortestPath); return(shortestPath.Select((edge => new RoutingSegment(edge.Source, edge.Target, edge.NavigationMode))) .ToList()); }
void Awake() { stateInput = new StateInput(); controller = GetComponent <CharacterController2D>(); currentPoint = firstNavigationPoint; controller.SetFacingDirection(initialFacingDirection != FacingDirection.Left); }
/// <summary> /// Adds given node to list. /// Creates list if given list was null. /// </summary> /// <param name="point">Node to add to the list.</param> /// <param name="currentRoute">Current RouteList.</param> /// <returns>NavigationPoint list with added node.</returns> private List <NavigationPoint> AddToList(NavigationPoint point, List <NavigationPoint> currentRoute) { if (currentRoute == null) { currentRoute = new List <NavigationPoint>(); } currentRoute.Add(point); return(currentRoute); }
void handleOnNavTrigger(NavigationPoint navTrigger) { //We go to exitingLevel state if the navigation trigger triggered by the PC is an exit if (navTrigger.isExit) { sceneToLoad = navTrigger.exitToScene; goExitingLevel(); } }
public void ToString_WithoutIdInFile_ReturnsStringRepresentationWithoutId() { var name = "Chapter 1"; var file = TestItemFactory.CreateFileFromString("test.txt"); string elementId = null; var testee = new NavigationPoint(name, file, elementId, 0, new NavigationPoint[0]); var result = testee.ToString(); Assert.AreEqual("Chapter 1 - test.txt", result); }
private NavigationPoint PrepareNavigationPoint(NavigationPoint navigationPoint) { var np = new NavigationPoint(); Array.Copy(ToBigEndian(navigationPoint.Name), np.Name, np.Name.Length); np.Executable = navigationPoint.Executable; np.PrPro = navigationPoint.PrPro; np.Type = navigationPoint.Type; np.GeoCoordinate = navigationPoint.GeoCoordinate; np.Measure = navigationPoint.Measure; return(np); }
private float EvaluateCost(NavigationPoint navPoint, NavigationAgent agent, Vector3 nextPathPoint) { switch (_navigationType) { case NavigationType.ByUnityNavMeshPath: return(2 * Vector3.Distance(navPoint.position, agent.transform.position) + 3f * Vector3.Distance(navPoint.position, nextPathPoint) + 0.5f * Vector3.Distance(navPoint.position, _player.position)); case NavigationType.SimpleNearestPoint: default: return(1 * Vector3.Distance(navPoint.position, agent.transform.position) + 2f * Vector3.Distance(navPoint.position, _player.position)); } }
private float CompositeTotalDangerScore(RaycastHit[] detectedObjects) { float totalDangerScore = 0; foreach (RaycastHit hitInfo in detectedObjects) { NavigationPoint currentNavPoint = hitInfo.collider.gameObject.GetComponent <NavigationPoint>(); totalDangerScore += currentNavPoint.dangerScore; } return(totalDangerScore); }
internal void ShowPrevious() { // Shows the previous item in a pad that implements ILocationListPad. if (activeLocationList != null) { NavigationPoint next = activeLocationList.GetPreviousLocation(); if (next != null) { next.ShowDocument(); } } }
internal void ShowNext() { // Shows the next item in a pad that implements ILocationListPad. if (activeLocationList != null) { NavigationPoint next = activeLocationList.GetNextLocation(); if (next != null) { next.Show(); } } }
void Start() { HomePoint = new NavigationPoint(new Color(0, 1, 0, 0.8f), "Home", true, HomePointObject); /* * NavigationPoint point1 = new NavigationPoint(new Color(1, 0, 0, 0.8f), "Point Red", true, HomePointObject); * navigationPoints.Add(point1); * NavigationPoint point2 = new NavigationPoint(new Color(1,1, 1, 0.8f), "Point White", true, HomePointObject); * navigationPoints.Add(point2); * NavigationPoint point3 = new NavigationPoint(new Color(1, 0.5f, 0.5f, 0.8f), "Point Pink", true, HomePointObject); * navigationPoints.Add(point3); */ }