public void Update() { if (doChase) { oneTimeChase = true; doChase = false; } if (oneTimeChase) { next = GameManager.GetAllPoints()[RandomManager.Instance.Random.Next(0, GameManager.GetPointsCount())]; oneTimeChase = !oneTimeChase; } owner.ComputePath(LevelManager.CurrentMap, (int)((next as TargetPoint).Transform.Position.X + 0.5f), (int)((next as TargetPoint).Transform.Position.Y + 0.5f)); if ((next.Location - owner.Transform.Position).Length < 1f || owner.CurrentPath == null) { oneTimeChase = !oneTimeChase; } if (owner.CurrentPath == null) { return; } if (owner.CurrentPath.Count == 0) { owner.CurrentPath = null; return; } owner.ExecutePath(); }
public bool TryGetWaypointInDirection(Vector2 direction, out IWaypoint waypoint) { List <WaypointSign> result = new List <WaypointSign>(); foreach (var waypointSign in WaypointSigns) { float angle = waypointSign.GetAngle(); Vector2 a = waypointSign.FromConstraint.normalized; Vector2 b = Quaternion.Euler(0, 0, angle) * a; float aXb = Vector2.Dot(a, b); float aXc = Vector2.Dot(a, direction); float cXb = Vector2.Dot(direction, b); float cXa = Vector2.Dot(direction, a); if (aXb * aXc >= 0f && cXb * cXa >= 0f && angle <= 180f) { result.Add(waypointSign); } } if (result.Count == 1) { waypoint = result[0].Waypoint; return(false); } else { waypoint = null; return(false); } }
/// <summary> /// Checks what type parameters the waypoint holds and sets color accordingly /// </summary> /// <param name="wp"></param> /// <returns></returns> public static Color GetWaypointColor(IWaypoint wp) { // check if its correct type of waypoint if (wp is RndfWayPoint) { // cast RndfWayPoint waypointData = (RndfWayPoint)wp; // assign color based upon parameters if (waypointData.IsStop && waypointData.IsCheckpoint) { return(CheckStopColor); } else if (waypointData.IsCheckpoint) { return(CheckpointColor); } else if (waypointData.IsStop) { return(StoplineColor); } else { return(WaypointColor); } } else if (wp is UserWaypoint) { return(UserWaypointColor); } else { throw new ArgumentException("argument not WaypointData type", "wp"); } }
private void RaiseWaypointChanged(IWaypoint previousWaypoint, IWaypoint currentWaypoint) { if (this.OnWaypointChanged != null) { this.OnWaypointChanged(previousWaypoint, currentWaypoint); } }
void CheckLineConfiguration(IWaypoint from, IWaypoint to) { var startPoint = ConnectorUtilities.ComputePoint(from.Bounds, from.OutgoingDocking, from.OutgoingRelativePosition); var endPoint = ConnectorUtilities.ComputePoint(to.Bounds, to.IncomingDocking, to.IncomingRelativePosition); var pos = ConnectorUtilities.ComputeRelativePositionOfPoints(startPoint, endPoint); LineType lineType = (LineType)((int)from.OutgoingDocking << 8 | (int)to.IncomingDocking); if (AllowedRelativePositions.Table.TryGetValue(lineType, out SortedSet <RelativePosition> possibleConfigurations)) { if (!possibleConfigurations.Contains(pos)) { if (_model.CanMoveStart) { from.OutgoingDocking = ConnectorDocking.Undefined; } if (_model.CanMoveEnd) { to.IncomingDocking = ConnectorDocking.Undefined; } } } else { if (_model.CanMoveStart) { from.OutgoingDocking = ConnectorDocking.Undefined; } if (_model.CanMoveEnd) { to.IncomingDocking = ConnectorDocking.Undefined; } } }
void Update() { // make sure the guide keeps within the given following distance of the car if ((car.transform.position - transform.position).magnitude <= followDistance) { Vector3 remainingDistance = waypoint.Position - transform.position; if (remainingDistance.magnitude <= waypoint.ArrivedDistance) { if (!(getRedNS() && collideValNS) && !(getRedWE() && collideValWE)) { IWaypoint nextWaypoint = waypoint.GetNext(); if (nextWaypoint != null) { waypoint.SetCar(null); waypoint = nextWaypoint; waypoint.SetCar(gameObject); } } } else { transform.Translate(remainingDistance.normalized * speed * Time.deltaTime); } } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// creates an instance of node with a certain waypoint /// </summary> /// <param name="waypoint">to create node for</param> public Node(IWaypoint waypoint) { this.Waypoint = waypoint; Parent = null; G = 0; H = 0; }
private IEnumerator AddEdge(Collision collision) { IWaypoint target = collision.transform.parent.GetComponent <WaypointController>().waypoint; yield return(missionRef.AddEdge(source, target)); GameObject.Destroy(this.gameObject); }
public int GetCountBehind(IWaypoint waypoint, bool loop = false) { if (loop) { return(this.waypoints.Count - 1); } return(this.GetIndexOf(waypoint)); }
/// <summary> /// Constructor /// </summary> /// <param name="DistanceFromLowerBound">Distance the of the blockage from hte LowerBound Waypoint</param> /// <param name="BlockageID">Identifier with which to modify the blockage</param> /// <param name="LowerBound">Waypoint blockage exists after</param> /// <param name="UpperBound">Waypoint blockage exists before</param> /// <param name="ProbabilityExists">Initial probability with which the blockage exists</param> /// <param name="BlockageContainer">Interconnect or Partition of Lane taht holds the blockage</param> public Blockage(double DistanceFromLowerBound, IConnectWaypoints BlockageContainer, string BlockageID, IWaypoint LowerBound, IWaypoint UpperBound, double ProbabilityExists) { this.DistanceFromLowerBound = DistanceFromLowerBound; this.BlockageContainer = BlockageContainer; this.BlockageID = BlockageID; this.LowerBound = LowerBound; this.UpperBound = UpperBound; this.ProbabilityExists = ProbabilityExists; }
public static bool IsLast(this IWaypointPath path, IWaypoint waypoint) { if (path.Count > 0 && waypoint == path[path.Count - 1]) { return(true); } return(false); }
public PathRequest(IPathRequester pathRequester, PathValues pathValues, IWaypoint wayPoint, Func <Vector2[]> pathCreation, Action <bool> pathCompleteCallback) { PathCreation = pathCreation; PathValues = pathValues; PathRequester = pathRequester; PathCompleteCallback = pathCompleteCallback; WayPoint = wayPoint; }
/// <summary> /// Removes all waypoints on the path ahead of <paramref name="waypoint"/>. /// </summary> /// <param name="path">The current waypoint path.</param> /// <param name="waypoint">The waypoint from which to remove waypoints from.</param> public static void TrimAhead(this IWaypointPath path, IWaypoint waypoint) { var startIndex = path.GetIndexOf(waypoint); for (var i = startIndex + 1; i < path.Count; i++) { path.RemoveAtIndex(i); } }
/// <summary> /// Constructor /// </summary> /// <param name="distanceFromLowerBound">distance of the vehicle's projected absolutePosition from the closest lowerBound IWaypoint on the Lane</param> /// <param name="partition">the lanePartition of Interconnect the vehicle can reference itself in</param> /// <param name="lowerBound">closest user or rndf waypoint previous to absolutePosition on lane</param> /// <param name="upperBound">closest user or rndf waypoint after absolutePosition on lane</param> /// <param name="offset">distance of hte vehicle's absolute absolutePosition from the lane's supposed absolutePosition</param> /// <param name="relativeRndfPosition">the absolute absolutePosition of the vehicle on the rndf in x,y</param> /// <param name="error">if the absolute absolutePosition is not perfectly offset, there is an error</param> public LocationAnalysis(double distanceFromLowerBound, IConnectWaypoints partition, IWaypoint lowerBound, IWaypoint upperBound, double offset, Coordinates relativeRndfPosition, double error) { this.distanceFromLowerBound = distanceFromLowerBound; this.partition = partition; this.lowerBound = lowerBound; this.upperBound = upperBound; this.offset = offset; this.relativeRndfPosition = relativeRndfPosition; this.error = error; }
/// <summary> /// Constructor /// </summary> /// <param name="partition">Partition of the RndfNetwork the vehicle is a part of</param> /// <param name="lowerBound">Specific previous waypoint bounding the vehicle</param> /// <param name="upperBound">Specific next waypoint bounding the vehicle</param> /// <param name="offset"></param> /// <param name="error">Error value associated with the location</param> /// <param name="absolute">Absolute position of the vehicle on the rndfNetwork map</param> /// <param name="laneConfidence">Confidence the vehicle should be processed according to this lane</param> public RndfLocation(IConnectWaypoints partition, IWaypoint lowerBound, IWaypoint upperBound, double offset, double error, Coordinates absolute, double laneConfidence) { this.partition = partition; this.lowerBound = lowerBound; this.upperBound = upperBound; this.offset = offset; this.error = error; this.absolutePositionOnPartition = absolute; this.laneConfidence = laneConfidence; }
public void Add(IWaypoint waypoint) { // Debug.LogFormat("Adding waypoint {0}", waypoint); this.waypoints.Add(waypoint); if (this.OnWaypointAdded != null) { this.OnWaypointAdded(waypoint); } }
public IWaypoint GetPrevious(IWaypoint waypoint, bool loop = false) { IWaypoint previous; if (!this.TryGetPrevious(waypoint, out previous, loop)) { throw new InvalidOperationException(string.Format("Could not get the waypoint before {0} because there is no preceeding waypoint", waypoint)); } return(previous); }
/// <summary> /// initialised the variables for a new search /// </summary> /// <param name="start">the waypoint to start from</param> /// <param name="goal">the destination waypoint</param> /// <param name="agent">the agent to use for path</param> private void Init(IWaypoint start, IWaypoint goal, IAgent agent) { open = new PriorityQueue <float, Node>(256); closed = new Hashtable(); existing = new Hashtable(); Node startNode = new Node(start); startNode.H = start.EstimateCost(goal, agent); open.Add(0, startNode); existing.Add(start, startNode); }
protected override void OnAwake() { touchRegion = transform.Find("TouchRegion").gameObject.GetComponentStrict <BoxCollider2D>(); GameObject spellGameObject = transform.Find("SpellButton").gameObject; spellRegion = spellGameObject.GetComponentStrict <BoxCollider2D>(); spellButton = spellGameObject.transform.Find("spellbutton").GetComponentStrict <SpriteWrapper>(); cooldownText = spellGameObject.transform.Find("cooldowntext").GetComponentStrict <Text>(); moveGrid = transform.Find("MoveGrid").gameObject.GetComponentStrict <MoveGrid>(); waypoint = Game.Resources.LoadPrefab <Waypoint>("Waypoints/Waypoint"); }
public int GetIndexOf(IWaypoint waypoint) { var index = this.waypoints.IndexOf(waypoint); if (index == -1) { throw new InvalidOperationException(string.Format("Could not get the waypoint following {0} because it does not exist in the path", waypoint)); } return(index); }
public IWaypoint GetNext(IWaypoint waypoint, bool loop = false) { IWaypoint next; if (!this.TryGetNext(waypoint, out next, loop)) { throw new InvalidOperationException(string.Format("Could not get the waypoint after {0} because there is no next waypoint", waypoint)); } return(next); }
public WaypointMoveOperation(ConnectorUI ui, Point startPoint, IWaypoint wp) { _ui = ui; _wp = wp; _startPoint = startPoint; _ui.TriggerSnapshot(); _ui.MouseMove += Ui_MouseMove; _ui.MouseUp += Ui_MouseUp; _ui.CaptureMouse(); }
public bool TryGetAtIndex(int index, out IWaypoint waypoint) { if (this.waypoints.Count == 0 || this.waypoints.Count <= index || index < 0) { waypoint = null; return(false); } waypoint = this.waypoints[index]; return(true); }
public void ArrowClicked(IWaypoint targetWaypoint) { IBranchDecisionResult result = new BranchDecisionResult(targetWaypoint); AnswerCallBack(result); AnswerCallBack = null; for (int i = Arrows.Count - 1; i >= 0; i--) { GameObject.Destroy(Arrows[i]); } }
public EnemySpawner(IWaypoint player) : base("AI Spawner") { this.Player = player; for (int i = 0; i < Map.GetEnemySpawnPoints().Count(); i++) { IEnemy enemy = EnemyFactory.Get(EnemyType.Balloom); enemy.Player = (Bomberman)player; enemy.RefTransform.Position = Map.GetEnemySpawnPoints()[RandomManager.Instance.Random.Next(0, Map.GetEnemySpawnPoints().Count())]; GameObject.Spawn((GameObject)enemy); } }
public BingWaypoint(IWaypoint wp) { if (wp.HasCoordinate) { Coordinate = BingCoordinate.ToBing(wp.GetCoordinate()); } if (wp.HasAddress) { Address = wp.GetAddress(); } WaypointType = wp.WaypointType; IsViaPoint = wp.WaypointType == WaypointType.ViaPoint; }
public static BingWaypoint ToBing(IWaypoint wp) { if (wp == null) { return(null); } if (wp is BingWaypoint bwp) { return(bwp); } return(new BingWaypoint(wp)); }
private void OnWaypointChanged(IWaypoint previousWaypoint, IWaypoint currentWaypoint) { if (this.ObjectiveChanged != null) { var previousObjective = previousWaypoint == null ? null : ((ObjectiveWaypoint)previousWaypoint).Objective; var currentObjective = currentWaypoint == null ? null : ((ObjectiveWaypoint)currentWaypoint).Objective; this.ObjectiveChanged(this, previousObjective, currentObjective); } }
public void DrawHandles(IWaypoint waypoint) { Vector3 fromConstraint3 = FromConstraint; Vector3 toConstraint3 = ToConstraint; ToConstraint = Handles.PositionHandle(toConstraint3 + waypoint.Position, Quaternion.identity) - waypoint.Position; FromConstraint = Handles.PositionHandle(fromConstraint3 + waypoint.Position, Quaternion.identity) - waypoint.Position; float angle = GetAngle(); Handles.color = Color; Handles.DrawSolidArc(waypoint.Position, Vector3.forward, FromConstraint, angle, 1f); Handles.DrawLine(waypoint.Position, waypoint.Position + fromConstraint3); Handles.DrawLine(waypoint.Position, waypoint.Position + toConstraint3); }
public void Init(IWaypoint wp, MissionController missionController, bool addUXTasks = true) { if (wp != null) { waypoint = wp; this.transform.localPosition = waypoint.Pose.ToPositionVector(); } if (addUXTasks) { wp.AddTargetSetTask(new ColorChangeTask(this.gameObject, CurrentWaypointMaterial)); wp.AddExitTask(new ColorChangeTask(this.gameObject, NonCurrentWaypointMaterial)); } this.missionController = missionController; }
/// <summary> /// Checks what type parameters the waypoint holds and sets color accordingly /// </summary> /// <param name="wp"></param> /// <returns></returns> public static Color GetWaypointColor(IWaypoint wp) { // check if its correct type of waypoint if (wp is RndfWayPoint) { // cast RndfWayPoint waypointData = (RndfWayPoint)wp; // assign color based upon parameters if (waypointData.IsStop && waypointData.IsCheckpoint) { return CheckStopColor; } else if (waypointData.IsCheckpoint) { return CheckpointColor; } else if (waypointData.IsStop) { return StoplineColor; } else { return WaypointColor; } } else if(wp is UserWaypoint) { return UserWaypointColor; } else { throw new ArgumentException("argument not WaypointData type", "wp"); } }
/// <summary> /// Analyzes a specific partition to set closeness values /// </summary> /// <param name="coordinate">coordinate to analyze the lane partition</param> /// <param name="initial">initial waypoint of the partition</param> /// <param name="final">final waypoint of the partition</param> /// <returns>vector consisting of relative and absolute partition localization information</returns> /// <remarks> /// In analyzing partitions, the nearest point might be one of the endpoints of the /// partition, rather than the closest point on the line. Defining the vehicle's absolutePosition as C, /// the initial waypoint of the partition as A and the final Waypoint of the partition as B, /// the closest point to C on the line defined by A and B is might not /// be on the segment AB, so the point closest to C is B or A. /// While there are a few different ways to check for this special case, /// one way is to apply the dot product. /// /// First, check to see if the nearest /// point on the line AB is beyond B (as in the example above) by taking /// AB dot BC. If this value is greater than 0, it means that the angle /// between AB and BC is between -90 and 90, exclusive, and therefore /// the nearest point on the segment AB will be B. Similarly, if BA dot AC /// is greater than 0, the nearest point is A. If both dot products are /// negative, then the nearest point to C is somewhere along the partiton. /// </remarks> private static LocationAnalysis AnalyzePartition(Coordinates coordinate, IWaypoint initial, IWaypoint final) { #region Check if coordinates closest absolutePosition on partition is within the partition // Check if coordinate is outside of B Coordinates AB = final.Position - initial.Position; Coordinates BC = coordinate - final.Position; bool closestB = AB.Dot(BC) > 0; // Check if coordinate is outside of A Coordinates BA = initial.Position - final.Position; Coordinates AC = coordinate - initial.Position; bool closestA = BA.Dot(AC) > 0; // Check if coordinate is inside segment (not outside of A or B) bool insidePartition = !closestA && !closestB; #endregion // if in partition if (insidePartition) { // get unit vector of partition Coordinates unitPartition = AB / AB.Length; // project coordinate onto the partition Coordinates deltaProjection = AC.Dot(unitPartition) * unitPartition; // get distance along partition double distance = deltaProjection.Length; // get final point Coordinates closestPoint = initial.Position + deltaProjection; // get offset Coordinates difference = coordinate - closestPoint; double offset = difference.Length; // set the return vector return (new LocationAnalysis(distance, null, initial, final, offset, closestPoint, 0)); } else if (closestA) { // closest point is initial Coordinates closestPoint = initial.Position; // distance along is 0 as initial point double distanceAlong = 0; // offset is 1234567 as not perfectly offset double offset = 1234567; // calculate error double errorSize = AC.Length; // set the return vector return (new LocationAnalysis(distanceAlong, null, initial, final, offset, closestPoint, errorSize)); } else if (closestB) { // closest point is initial Coordinates closestPoint = final.Position; // distance along is 0 as initial point double distanceAlong = 0; // offset is 1234567 as not perfectly offset double offset = 1234567; // calculate error double errorSize = BC.Length; // set the return vector return (new LocationAnalysis(distanceAlong, null, initial, final, offset, closestPoint, errorSize)); } return null; }