protected void FlyTowardsGameObjectInRange(GameObject theDestination) { if (LibRevel.IsNotWithinDistanceThreshold(gameObject, theDestination, distanceThreshold)) { LibRevel.FlyTowardsGameObjectIgnoringAxes(gameObject, theDestination, MovementSpeed * RateModifier, ignoreY: true); } else { ApplyBrakes(); } }
protected bool IsWithinBrakingDistance(GameObject destination) { bool result = false; if (LibRevel.IsNotWithinDistanceThreshold(transform.position, destination.transform.position, (distanceThreshold + (rigidbody.velocity.magnitude /* * 2*/)))) { //If it is outside of the threshold... result = false; //Return false. - Moore } else { // Otherwise, return true. - Moore return(true); } return(result); }
void Update() { //Done cycling through options based on the state. This is now based on the ship's type. switch (shipType) { case ShipType.Alpha: { //Only the player gains interest and communicates with the GameController. if (theGameControllerScript != null) { //Bank the interest from existing resources. ResourceLoad += ResourceLoad * interestRate * Time.deltaTime; } break; } case ShipType.Node: { //Only the player gains interest and communicates with the GameController. if (ResourceLoad <= 0) { //Destroy(gameObject); ResourceLoad += Random.Range(500, 1500); if (theGameControllerScript != null) { transform.position = LibRevel.RandomVector3InRange(theGameControllerScript.MinBoundX, theGameControllerScript.MaxBoundX, 0, 0, theGameControllerScript.MinBoundZ, theGameControllerScript.MaxBoundZ); } } break; } //Interceptors should occasionally attack other units. //Freighters don't have much in the way of special behavior, but may cause resource nodes to appear when attacked? //To make the AI smarter, maybe consider having them drop to the nearest freighter instead of the player if the freighter is closer. - Moore //Resonators should spend some of their Resource load to boost other allied units. default: break; } }
// Update is called once per frame void FixedUpdate() { switch (state) { case State.Dummy: break; case State.Stay: //Distinct from dummy. If this unit has distinct behaviors like attacking, it should still perform those duties... just not in this script. - Moore ApplyBrakes(); break; case State.FollowPlayer: target = LibRevel.FindClosestGameObjectWithTag(gameObject, "Player"); FlyTowardsGameObjectWithSmartBraking(target); break; case State.GatherNearestResourcePoint: //Search for the nearest resource point. - Moore target = LibRevel.FindClosestGameObjectWithTag(gameObject, "ResourcePoint"); //If close enough, draw resources from it. If not, then fly closer. - Moore if (LibRevel.IsWithinDistanceThreshold(gameObject, target, distanceThreshold)) { ApplyBrakes(); GatherResourcesFromSource(target); } else { FlyTowardsGameObjectWithSmartBraking(target); } //If my resources are maxed out, return to the alpha ship (player) - Moore. if (ResourceLoad >= resourceCapacity) { state = State.DropoffAtFreighter; } break; case State.ReturnToBase: target = LibRevel.FindClosestGameObjectWithTag(gameObject, "Player"); //This had been planned to be a separate ship, but now it refers to the player. - Moore if (LibRevel.IsWithinDistanceThreshold(gameObject, target, distanceThreshold)) { ApplyBrakes(); TransferResourcesToSource(target); //If you're close enough to the player, drop off your resources until you're empty. - Moore } else { FlyTowardsGameObjectWithSmartBraking(target); //If you're not close enough, get closer. - Moore. } //If no more resources to deposit, go back to the default behavior of following the player. if (ResourceLoad <= 0.0f) { state = State.FollowPlayer; } break; case State.DropoffAtFreighter: target = LibRevel.FindClosestGameObjectWithTag(gameObject, "Freighter"); altTarget = LibRevel.FindClosestGameObjectWithTag(gameObject, "Player"); if (target != null && altTarget != null) { //Change the target to point at the same thing as the altTarget if the altTarget is closer. if (Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(target.transform.position.x, target.transform.position.z)) > Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(altTarget.transform.position.x, altTarget.transform.position.z))) { target = altTarget; } } else if (target == null) { target = altTarget; } if (LibRevel.IsWithinDistanceThreshold(gameObject, target, distanceThreshold)) { ApplyBrakes(); TransferResourcesToSource(target); //If you're close enough to the player, drop off your resources until you're empty. - Moore } else { FlyTowardsGameObjectWithSmartBraking(target); //If you're not close enough, get closer. - Moore. } //If no more resources to deposit, go back to the default behavior of following the player. if (ResourceLoad <= 0.0f) { state = State.FollowPlayer; } break; default: { break; } } //Any time the state changes, update the status indicator. if (prevState != state) { UpdateStatusIndicator(); prevState = state; } }