Exemplo n.º 1
0
    // need to ensure projectile is clear
    // of player and player's orbiting objects.
    // might switch to non-physics-based implementations...
    void Throw()
    {
        if (throwables.Count > 0)
        {
            Humanoid possibleTarget = null;
            float    minAngle       = Mathf.Infinity;

            foreach (Humanoid h in humanoids)
            {
                if (!h.GetIsStaggered())
                {
                    Vector3 positionOfHumanoid = h.GetPosition();
                    Vector3 direction          = positionOfHumanoid - transform.position;
                    float   distance           = direction.magnitude;

                    if (distance < 30f)
                    {
                        float angleToHumanoid
                            = Vector3.Angle(direction, transform.forward);

                        if (angleToHumanoid
                            < minAngle)
                        {
                            minAngle       = angleToHumanoid;
                            possibleTarget = h;
                        }
                    }
                }
            }
            Vector3 shootHere = Vector3.zero;
            // if there is a target
            if (possibleTarget != null)
            {
                shootHere = possibleTarget.GetPosition();
            }
            else
            {
                Ray ray = new Ray();
                ray.origin    = Camera.main.transform.position;
                ray.direction = Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    shootHere = hit.point;
                }
            }
            // find the IThrowable that is closest to the target.
            IThrowable throwThisOne = FindClosestThrowable(shootHere);
            throwThisOne.BecomeProjectile(shootHere);
        }
    }
Exemplo n.º 2
0
    public void BlockedAttack(Vector3 directionOfAttack)
    {
        IThrowable throwableThatBlockedAttack = FindClosestThrowable(directionOfAttack);

        Vector3 upOrDownVec  = Vector3.zero;
        bool    ricochetLeft = Random.value >= 0.5;

        if (ricochetLeft)
        {
            upOrDownVec = Vector3.up;
        }
        else
        {
            upOrDownVec = Vector3.down;
        }
        Vector3 perpVec   = Vector3.Cross(directionOfAttack, upOrDownVec).normalized;
        Vector3 shootHere = self.GetPosition() + perpVec * 5.0f;

        throwableThatBlockedAttack.BecomeProjectile(shootHere);
    }
    void Throw()
    {
        // check to see if you have something to throw.
        if (throwables.Count > 0)
        {
            Humanoid possibleTarget = null;
            float    minAngle       = Mathf.Infinity;
            // of all the humanoids in the level
            // check to see if any are in front of you and in distance.
            // if so find the one that is closest to being directly in
            // front of you.
            foreach (Humanoid h in humanoids)
            {
                // ignore staggered enemies.
                if (!h.GetIsStaggered())
                {
                    Vector3 positionOfHumanoid = h.GetPosition();
                    Vector3 direction          = positionOfHumanoid - transform.position;
                    float   distance           = direction.magnitude;

                    if (distance < 30f)
                    {
                        float angleToHumanoid
                            = Vector3.Angle(direction, transform.forward);

                        if (angleToHumanoid
                            < minAngle)
                        {
                            minAngle       = angleToHumanoid;
                            possibleTarget = h;
                        }
                    }
                }
            }

            Vector3 shootHere = Vector3.zero;
            // if there is a target
            if (possibleTarget != null)
            {
                shootHere = possibleTarget.GetPosition();
            }
            else
            {
                Ray ray = new Ray();
                ray.origin    = Camera.main.transform.position;
                ray.direction = Camera.main.transform.forward;

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    shootHere = hit.point;
                }
            }
            // find the IThrowable that is closest to the target.
            IThrowable throwThisOne        = null;
            float      minDistanceToTarget = Mathf.Infinity;
            foreach (IThrowable t in throwables)
            {
                Vector3 positionOfThrowable = t.GetPosition();
                Vector3 vectorToThrow       = shootHere - positionOfThrowable;
                float   distanceToThrow     = vectorToThrow.magnitude;
                if (minDistanceToTarget > distanceToThrow)
                {
                    minDistanceToTarget = distanceToThrow;
                    throwThisOne        = t;
                }
            }
            throwThisOne.BecomeProjectile(shootHere);
        }
    }