public MovementPlan GetStartingPlan(Vector2 currentMoveDirection, IUnit unit) { var moveDirection = unit != null ? ((Vector2)unit.Transform.position - unit.AngleDefinition.GetPointClosestTo(_player.transform.position)).normalized : currentMoveDirection; var targetLocation = unit?.AngleDefinition.GetPointClosestTo(_player.transform.position) ?? StartingTargetLocation(_player.transform.position, moveDirection); targetLocation = BoundaryHelper.HandleBoundaryCollision(targetLocation, moveDirection); // Obstacle start position = mover.position // Target end position = targetLocation (only adjust if there is no unit) _currentIntersections = _intersectionDetector.GetIntersectionsFromUnit(unit); var startingPlanValues = new MovementPlanValues(targetLocation, moveDirection, unit, _currentIntersections); var startingPlanStates = new MovementPlanStates(false, unit == null, false); var movementPlan = new MovementPlan(startingPlanValues, startingPlanStates); movementPlan.SetFirst(); OnFirstMove?.Invoke(1); return(EditMovementPlanForObstacles(movementPlan, _player.transform.position)); }
public MovementPackage(Transform mover, Destination destination, float distanceScalar) { _mover = mover; MovementCount++; DistanceScalar = distanceScalar; Destination = destination; Destination.TargetLocation = BoundaryHelper.HandleBoundaryCollision(Destination.TargetLocation, destination.MoveDirection); if (BoundaryHelper.WillBeMovingThroughBoundary(_mover.transform.position, Destination.TargetLocation)) { Destination = null; } if (Vector2.Distance(destination.TargetLocation, mover.transform.position) > 0.1f) { OnFirstMove?.Invoke(); } }
public MovementPackage(Destination destination, IntersectionAnalysis previousIntersectionAnalysis, Transform mover, float distanceScalar) { MovementCount++; DistanceScalar = distanceScalar; _mover = mover; Destination = destination; IntersectionAnalysis = ShouldUsePreviousIntersections(previousIntersectionAnalysis) ? previousIntersectionAnalysis : new IntersectionAnalysis(destination); _parallelAnalysis = new ParallelAnalysis(Destination, distanceScalar); IntersectionAnalysis.DrawIntersectionVectors(); Evaluate(distanceScalar); LocationBeforeCollisionAdjustment = Destination.TargetLocation; Destination.TargetLocation = BoundaryHelper.HandleBoundaryCollision(Destination.TargetLocation, destination.MoveDirection); BoundaryPathFinder = new BoundaryPathFinder(_mover, Destination); }
public MovementPlan FinishPlanOrMoveToNextIntersect(MovementPlan previousPlan) { MovementPlan movementPlan; if (previousPlan.ValidIntersections()) { _currentIntersections = previousPlan.CurrentIntersections; var targetUnit = _currentIntersections.Dequeue(); var targetLocation = targetUnit.AngleDefinition.IntersectionPoint; // Obstacle start position = previousPlan.TargetLocation // Target end position = targetLocation (never adjusted) var nextIntersectionMovementValues = new MovementPlanValues(targetLocation, previousPlan.MoveDirection, targetUnit, _currentIntersections); var nextIntersectionMovementStates = new MovementPlanStates(true, false, false); movementPlan = new MovementPlan(nextIntersectionMovementValues, nextIntersectionMovementStates); return(EditMovementPlanForObstacles(movementPlan, previousPlan.TargetLocation)); } var finishedTargetPosition = FinishedTargetLocation(previousPlan.TargetLocation, previousPlan.MoveDirection); finishedTargetPosition = BoundaryHelper.HandleBoundaryCollision(finishedTargetPosition, previousPlan.MoveDirection); // Obstacle start position = previousPlan.TargetLocation // Target end position = Adjusted(finishedTargetPosition); var finishedMovementValues = new MovementPlanValues(finishedTargetPosition, previousPlan.MoveDirection, null, null); var finishedMovementStates = new MovementPlanStates(false, true, false); movementPlan = new MovementPlan(finishedMovementValues, finishedMovementStates); return(EditMovementPlanForObstacles(movementPlan, previousPlan.TargetLocation)); }