private double alignmentToObjective(Vector3 objective) { var currentPosition = _current.position; var relativeAngle = Util.angleBetweenVec( currentPosition.x, objective.x, currentPosition.z, objective.z); relativeAngle -= _current.rotation.eulerAngles.y; if (relativeAngle < -180) { relativeAngle += 360; } else if (relativeAngle > 180) { relativeAngle -= 360; } if (relativeAngle > MINIMUM_PRECISION_ANGLE / 2) { _movementRotationState = MovementRotationState.LEFT; } else if (relativeAngle < -MINIMUM_PRECISION_ANGLE / 2) { _movementRotationState = MovementRotationState.RIGHT; } else { _movementRotationState = MovementRotationState.NONE; } return(relativeAngle); }
public AIBehaviour(Transform unit, bool isSharpshooter) { _current = unit; _isSharpshooter = isSharpshooter; _players = new List <GameObject>(GameObject.FindGameObjectsWithTag(PLAYER_TAG)); changeActionState(ActionState.WAITING); _movementRotationState = MovementRotationState.NONE; _movementTranslationState = MovementTranslationState.NONE; _targetActive = false; _cooldownTime = 0f; _isFiring = false; _cannonCooldown = 0f; _pointOfInterest = _current.position; }