Exemplo n.º 1
0
    bool CheckForBackStab(Action slot)
    {
        //If the weapon has no back stab ability, skip
        if (!slot.canBackStab)
        {
            return(false);
        }

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

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

        if (Physics.Raycast(origin, raycastDir, out hit, 1, ignoreLayers))
        {
            backStabTarget = hit.transform.GetComponentInParent <EnemyStates>();
        }

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

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

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

        Debug.Log("Backstab angle: " + angle);

        if (angle > 150)
        {
            //Get target position
            Vector3 targetPos = direction * backStabOffset;
            targetPos         += backStabTarget.transform.position;
            transform.position = targetPos;

            backStabTarget.transform.rotation = transform.rotation;
            backStabTarget.IsGettingBackStabbed(slot, inventoryManager.GetCurrentWeapon(slot.mirror));
            onEmpty   = false;
            canMove   = false;
            canAttack = false;
            inAction  = true;
            animator.SetBool(StaticStrings.animParam_Mirror, slot.mirror);
            animator.CrossFade(StaticStrings.animParam_ParryAttack, 0.2f);
            lockOnTarget = null;
            return(true);
        }

        return(false);
    }