private float NextMoveDirection(GoatMovementController targetGoat) { // GoatMovementController closestGoat = GetClosestGoat(); // _closestGoatTransform = closestGoat.transform; var targetGoatTransform = targetGoat.transform; return(targetGoatTransform.position.x > _trollTransform.position.x ? 1 : -1); }
public float NextMove() { Hooks hooks = GameController.Instance.Hooks; GoatControllerArray = GameController.Instance.GoatControllerArray; if (hooks.LeftBound != null && hooks.RightBound != null) { float leftBoundX = hooks.LeftBound.transform.position.x; float rightBoundX = hooks.RightBound.transform.position.x; Func <GoatMovementController, bool> goatIsValidTarget = goat => { bool goatWithinTrollTerritory = (goat.transform.position.x > leftBoundX && goat.transform.position.x < rightBoundX); bool goatIsWithinDistanceThreshold = Vector3.Distance(_trollTransform.position, goat.transform.position) <= _distanceThreshold; return(goatWithinTrollTerritory || goatIsWithinDistanceThreshold); }; IEnumerable <GoatMovementController> goatsByDistanceAscending = SortGoatsByDistanceAscending().Where(goatIsValidTarget); IEnumerable <GoatMovementController> goatsByMassDescending = SortGoatsByMassDescending().Where(goatIsValidTarget); if (!goatsByDistanceAscending.Any()) { return(0); } GoatMovementController closestGoat = goatsByDistanceAscending.First(); GoatMovementController heaviestGoat = goatsByMassDescending.First(); GoatMovementController targetGoat = heaviestGoat; return(NextMoveDirection(targetGoat)); } return(0f); }
public void EnableFollowing([NotNull] GoatMovementController goatToFollow) { _isFollowing = true; _followTarget = goatToFollow; }
public void DisableFollowing() { _isFollowing = false; _followTarget = null; }