Example #1
0
    private void Attack_started(UnityEngine.InputSystem.InputAction.CallbackContext obj)
    {
        if (Time.time > lastAttack + attackCooldown)
        {
            lastAttack = Time.time;

            Vector2 dir = controls.FreeMovement.Move.ReadValue <Vector2>();

            if (dir.Equals(Vector2.zero))
            {
                dir = new Vector2(axisFacing, 0);
            }

            float angle = Mathf.Atan2(dir.y, dir.x);
            bladoRotato.rotation = Quaternion.AngleAxis(angle * 180 / Mathf.PI, Vector3.forward);
            blade.Attack();
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (!controller.m_IsGrounded)
        {
            RaycastHit hitAssassination;

            if (!isAssassinating && !power_Blink.isBlinking && Physics.SphereCast(transform.position + Vector3.up * 0.5f, 1.2f, Vector3.down, out hitAssassination, 15, layerMaskAssassination))
            {
                if (hitAssassination.distance >= 2 && hitAssassination.transform.root.gameObject.layer == 9)   //Layer AI
                {
                    AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();

                    if (!AI_Behaviour.isDead && !AI_Behaviour.isUnconscious)
                    {
                        UI_ChokeAndKill.SetActive(true);
                        canAssassinate = true;

                        if (Input.GetButtonDown("Attack") || Input.GetAxis("Attack") > 0.2f)
                        {
                            isAssassinating               = true;
                            targetAssassination           = hitAssassination.transform.root;
                            targetAssassination.position += Vector3.up * 0.1f;
                            AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();
                            AI_Behaviour.AssassinationByKill();
                            blade.Attack();
                            speedMove = Vector3.Distance(transform.position, targetAssassination.position);
                        }

                        else

                        if (Input.GetButtonDown("Choke"))
                        {
                            isAssassinating               = true;
                            targetAssassination           = hitAssassination.transform.root;
                            targetAssassination.position += Vector3.up * 0.1f;
                            AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();
                            AI_Behaviour.AssassinationByChoke();
                            speedMove = Vector3.Distance(transform.position, targetAssassination.position);
                        }
                    }
                }

                else

                {
                    UI_ChokeAndKill.SetActive(false);
                    canAssassinate = false;
                }
            }

            else

            {
                UI_ChokeAndKill.SetActive(false);
                canAssassinate = false;
            }
        }

        else

        {
            canAssassinate = false;
        }

        if (isAssassinating)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetAssassination.position + Vector3.up * 0.8f - targetAssassination.forward * 0.2f, Time.deltaTime * speedMove * 1.5f);

            Quaternion orientation;
            orientation             = targetAssassination.rotation;
            orientation.eulerAngles = new Vector3(orientation.eulerAngles.x, orientation.eulerAngles.y + 180, orientation.eulerAngles.z);

            Quaternion orientationCam;
            orientationCam             = targetAssassination.rotation;
            orientationCam.eulerAngles = new Vector3(75, 0, 0);
            transform.rotation         = Quaternion.Slerp(transform.rotation, orientation, Time.deltaTime * 10);
            mainCamera.localRotation   = Quaternion.Slerp(mainCamera.localRotation, orientationCam, Time.deltaTime * 10);

            cam.fieldOfView = Mathf.MoveTowards(cam.fieldOfView, 35, Time.deltaTime * 30 * 2);

            timerAssassination += Time.deltaTime;
            mouseLook.canRotate = false;
            body.velocity       = new Vector3(0, body.velocity.y, 0);

            if (timerAssassination >= 1)
            {
                isAssassinating    = false;
                timerAssassination = 0;
                mouseLook.Init(transform, cam.transform);
                mouseLook.canRotate = true;
            }
        }
    }