/// <summary> /// Called to see if boosting is allowed at the moment /// </summary> /// <returns><c>true</c>, if boosting is allowed, <c>false</c> otherwise.</returns> /// <param name="currentMagnitude">Current magnitude</param> /// <param name="horizontalForce">Horizontal force</param> /// <param name="verticalForce">Vertical force</param> private bool _isBoostAllowed(float currentMagnitude, float horizontalForce, float verticalForce) { // First check if directional keys are down and you have energy // No need to even check additional logic if first level fails if ((Input.GetButton("Vertical") || Input.GetButton("Horizontal")) && _energyManager.getEnergy() >= boostCost) { // 1: If capped velocity and trying to head in the same direction the player is moving do not allow // 2: If the velocity is capped but you are trying to move another direction then allow it // 3: If not capped continue moving and also set previous direction if (currentMagnitude == maximumVelocity && _getDirection(horizontalForce, verticalForce) == _getDirection(_rigidbody.velocity.x, _rigidbody.velocity.y)) { return(false); } else if (currentMagnitude == maximumVelocity && _previousDirection != _getDirection(horizontalForce, verticalForce)) { return(true); } else if (currentMagnitude < maximumVelocity) { _previousDirection = _getDirection(horizontalForce, verticalForce); return(true); } } return(false); }