Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (!playerLife.GetDead())
        {
            // Calculates direction from object to cursor
            Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - weapon.position;
            direction.Normalize();

            // Verify player orientation
            float angle = (player.transform.localScale.x <= -1) ?
                          Mathf.Atan2(-direction.y, -direction.x) * Mathf.Rad2Deg
                : Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

            // Calculates new rotation
            Quaternion newRotation = Quaternion.AngleAxis(angle, Vector3.forward);

            // Spherically sets rotation
            weapon.rotation = Quaternion.Slerp(weapon.rotation, newRotation, rotationSpeed * Time.deltaTime);
            //Debug.Log(weapon.rotation.eulerAngles);

            // Attacks on mouse click
            if (Input.GetMouseButtonDown(0))
            {
                animator.ResetTrigger("Attacking");
                animator.SetTrigger("Attacking");
                Vector3 bRotation = (firePoint.position - weapon.position).normalized;
                gameObject.GetComponent <Shoot>().SpawnBullet(firePoint.position, bRotation);
            }
        }
    }
Example #2
0
    private bool duck   = false; //Duck

    // Update is called once per frame
    void Update()
    {
        if (!playerLife.GetDead())
        {
            ClearMovement();
            hMove = Input.GetAxisRaw("Horizontal") * rSpeed;
            if (Input.GetButtonDown("Jump"))
            {
                jump = true;
                animator.SetBool("Jumping", true);
                audioSource.Play();
            }

            animator.SetFloat("Speed", Mathf.Abs(hMove));

            /*
             * if (Input.GetButtonDown("Duck"))
             * { duck = true; } //hMove = 0f; //The temporary character shouldn't move while ducking but the definitive may
             * else if (Input.GetButtonUp("Duck"))
             *  duck = false;
             */
        }
        else
        {
            ClearMovement();
        }
    }