Пример #1
0
    public Vector3 GetPositionInBounds(float arrowAvoidance, float dragonAvoidanceRadius = 0.0f)
    {
        Vector3 positon     = BoxCollider.transform.position;
        Vector2 colliderPos = new Vector2(positon.x, positon.y) + BoxCollider.offset;
        float   randomPosX  = UnityEngine.Random.Range(colliderPos.x - BoxCollider.size.x / 2, colliderPos.x + BoxCollider.size.x / 2);
        float   randomPosY  = UnityEngine.Random.Range(colliderPos.y - BoxCollider.size.y / 2, colliderPos.y + BoxCollider.size.y / 2);
        Vector3 target      = new Vector3(randomPosX, randomPosY, positon.z);

        if (dragonAvoidanceRadius > 0.0f)
        {
            DebugLastTargetPosition = target;
        }
        if (Boomerang && Boomerang.Status == ArrowStatus.Landed)
        {
            if ((Boomerang.transform.position - target).sqrMagnitude < arrowAvoidance * arrowAvoidance)
            {
                const int MAX_ATTEMPT = 10;
                for (int attempt = 0; attempt < MAX_ATTEMPT; attempt++)
                {
                    float   angleStepSize = 360.0f / MAX_ATTEMPT;
                    float   rad           = angleStepSize * attempt * Mathf.Deg2Rad;
                    Vector3 Offset;
                    Offset.x = -(arrowAvoidance + 0.1f) * Mathf.Sin(rad);
                    Offset.y = (arrowAvoidance + 0.1f) * Mathf.Cos(rad);
                    Offset.z = 0.0f;

                    if (BoxCollider.bounds.Contains(Boomerang.transform.position + Offset))
                    {
                        target = Boomerang.transform.position + Offset;
                        break;
                    }
                }
            }
        }

        Vector3 bossPosition = bossBehaviour.transform.position + bossBehaviour.GetHalfSize();

        if ((bossPosition - target).sqrMagnitude < dragonAvoidanceRadius * dragonAvoidanceRadius)
        {
            const int MAX_ATTEMPT = 10;
            for (int attempt = 0; attempt < MAX_ATTEMPT; attempt++)
            {
                float   angleStepSize = 360.0f / MAX_ATTEMPT;
                float   rad           = angleStepSize * attempt * Mathf.Deg2Rad;
                Vector3 Offset;
                Offset.x = -(dragonAvoidanceRadius + 0.1f) * Mathf.Sin(rad);
                Offset.y = (dragonAvoidanceRadius + 0.1f) * Mathf.Cos(rad);
                Offset.z = 0.0f;

                if (BoxCollider.bounds.Contains(bossPosition + Offset))
                {
                    target = bossPosition + Offset;
                    break;
                }
            }
        }
        if (dragonAvoidanceRadius > 0.0f)
        {
            DebugLastFixedTargetPosition = target;
        }

        return(target);
    }