示例#1
0
        bool CheckForParry(Action slot)
        {
            if (!slot.canParry)
            {
                return(false);
            }

            EnemyStates parryTarget = null;
            Vector3     origin      = transform.position;

            origin.y += 1;
            Vector3    rayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(origin, rayDir, out hit, 3, ignoreLayers))
            {
                parryTarget = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (parryTarget == null)
            {
                return(false);
            }

            if (parryTarget.parriedBy == null)
            {
                return(false);
            }

            /*float dis = Vector3.Distance(parryTarget.transform.position, transform.position);
             *
             * if (dis > 3)
             *  return false;*/

            Vector3 dir = parryTarget.transform.position - transform.position;

            dir.Normalize();
            dir.y = 0;
            float angle = Vector3.Angle(transform.forward, dir);

            if (angle < 60)
            {
                Vector3 targetPosition = -dir * parryOffset;
                targetPosition    += parryTarget.transform.position;
                transform.position = targetPosition;

                if (dir == Vector3.zero)
                {
                    dir = -parryTarget.transform.forward;
                }

                Quaternion eRotation = Quaternion.LookRotation(-dir);
                Quaternion ourRot    = Quaternion.LookRotation(dir);

                parryTarget.transform.rotation = eRotation;
                transform.rotation             = ourRot;
                parryTarget.IsGettingParried(slot);
                canMove  = false;
                inAction = true;
                anim.SetBool(StaticStrings.mirror, slot.mirror);
                anim.CrossFade(StaticStrings.parry_attack, 0.2f);
                lockOnTarget = null;
                return(true);
            }

            return(false);
        }
示例#2
0
    bool CheckForParry(Action slot)
    {
        if (!slot.canParry)
        {
            return(false);
        }

        EnemyStates parryTarget = null;
        Vector3     origin      = transform.position;

        origin.y += 1;
        Vector3    raycastDir = transform.forward;
        RaycastHit hit;

        if (Physics.Raycast(origin, raycastDir, out hit, 3, ignoreLayers))
        {
            parryTarget = hit.transform.root.GetComponent <EnemyStates>();
        }

        if (parryTarget == null)
        {
            return(false);
        }

        if (parryTarget.parriedBy == null)
        {
            return(false);
        }

        //Direction towards the player
        Vector3 direction = parryTarget.transform.position - transform.position;

        direction.Normalize();
        direction.y = 0;
        float angle = Vector3.Angle(transform.forward, direction);

        Debug.Log("Parry angle: " + angle);
        if (angle < 60)
        {
            //Get target position
            Vector3 targetPos = -direction * parryOffset;
            targetPos         += parryTarget.transform.position;
            transform.position = targetPos;

            if (direction == Vector3.zero)
            {
                direction = -parryTarget.transform.forward;
            }

            //Make enemy look at player
            Quaternion enemyRot = Quaternion.LookRotation(-direction);
            parryTarget.transform.rotation = enemyRot;

            Quaternion playerRot = Quaternion.LookRotation(direction);
            transform.rotation = playerRot;

            parryTarget.IsGettingParried(slot, inventoryManager.GetCurrentWeapon(slot.mirror));

            onEmpty   = false;
            canMove   = false;
            canAttack = false;
            inAction  = true;
            animator.SetBool(StaticStrings.animParam_Mirror, slot.mirror);
            //animator.CrossFade("parry_attack", 0.2f);
            PlayAnimation(StaticStrings.animState_ParryReceived);
            lockOnTarget = null;
            return(true);
        }

        return(true);
    }