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 MovementPlan(MovementPlanValues movementPlanValues, MovementPlanStates movementPlanStates) { TargetLocation = movementPlanValues.TargetLocation; MoveDirection = movementPlanValues.MoveDirection; TargetUnit = movementPlanValues.TargetUnit; CurrentIntersections = movementPlanValues.Intersections; HeadingForObstacle = movementPlanStates.HeadingForObstacle; HeadingForIntersection = movementPlanStates.HeadingForIntersection; Finished = movementPlanStates.Finished; }
public MovementPlan GetPlanForNextMoveDuringObstaclePath(MovementPlan previousPlan) { var targetLocation = !_obstaclePathFinder.HasObstaclePath() ? _obstaclePathFinder.TargetLocationOnceFinishedWithObstaclePath : _obstaclePathFinder.NextPoint().ProjectedPoint; var moveDirection = !_obstaclePathFinder.HasObstaclePath() ? (_obstaclePathFinder.TargetLocationOnceFinishedWithObstaclePath - _obstaclePathFinder.PointBeforeStartingObstaclePath).normalized : (targetLocation - previousPlan.TargetLocation).normalized; var obstaclePlanValues = new MovementPlanValues(targetLocation, moveDirection, previousPlan.TargetUnit, previousPlan.CurrentIntersections); var obstaclePlanStates = new MovementPlanStates(previousPlan.HeadingForIntersection, previousPlan.TargetUnit == null, _obstaclePathFinder.HasObstaclePath()); return(new MovementPlan(obstaclePlanValues, obstaclePlanStates)); }
public MovementPlan PlanMovingTowardsIntersectingUnitFromPreviousIntersection(MovementPlan previousPlan) { var targetLocation = previousPlan.TargetUnit.AngleDefinition.GetPointClosestTo(_player.transform.position); var moveDirection = (targetLocation - previousPlan.TargetLocation).normalized; _currentIntersections = _intersectionDetector.GetIntersectionsFromUnit(previousPlan.TargetUnit); // Obstacle start position = previousPlan.TargetLocation // Target end position = targetLocation (never adjusted) var successfulRedirectionValues = new MovementPlanValues(targetLocation, moveDirection, previousPlan.TargetUnit, _currentIntersections); var successfulRedirectStates = new MovementPlanStates(false, false, false); var movementPlan = new MovementPlan(successfulRedirectionValues, successfulRedirectStates); return(EditMovementPlanForObstacles(movementPlan, previousPlan.TargetLocation)); }
private MovementPlan EditMovementPlanForObstacles(MovementPlan movementPlan, Vector2 fromPosition) { var obstaclePriority = _obstaclePathFinder.HasObstaclePath(); if (!obstaclePriority) { obstaclePriority = _obstaclePathFinder.FoundPath(fromPosition, movementPlan.TargetLocation, movementPlan.MoveDirection); } if (!obstaclePriority) { return(movementPlan); } var targetLocation = _obstaclePathFinder.NextPoint().ProjectedPoint; var targetMoveDirection = (targetLocation - fromPosition).normalized; var updatedPlanValues = new MovementPlanValues(targetLocation, targetMoveDirection, movementPlan.TargetUnit, _currentIntersections); var updatedPlanStates = new MovementPlanStates(movementPlan.HeadingForIntersection, movementPlan.Finished, true); return(new MovementPlan(updatedPlanValues, updatedPlanStates)); }
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)); }