Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        hit = false;
        Vector3 moveDir      = GetMoveDirection();
        Vector3 moveVelocity = moveDir * Time.deltaTime * playerSpeed * movementMultiplier;

        //set velocity in x and z plane
        playerVelocity.x = moveVelocity.x;
        playerVelocity.z = moveVelocity.z;

        //set velocity in the y direction
        playerVelocity += Physics.gravity * Time.deltaTime;
        if (controller.isGrounded)
        {
            playerVelocity.y = 0;
        }

        controller.Move(playerVelocity);
        Vector3 look = GetLookDirection();

        if (look != Vector3.zero)
        {
            Vector3 smoothedLook = Vector3.Lerp(transform.forward, look, smoothSpeed);
            transform.forward = smoothedLook;
        }
        // shoot bullet
        if (!shot && Input.GetAxis("Fire1") != 0)
        {
            shot = true;
            gun.Shoot();
        }
        else
        {
            shot = false;
        }
    }