Underwater movement Z-axis rotation

Hi all,

I’m making an underwater game (you’re a fish blub blub) and I made the movement an combination of keyboard and mouse.

The keyboard makes you go forward, backward and turn’s you left or right
The mouse pans you up and down

Now I only have a problem witch I can’t solve. If I use my script with both the mouse and keyboard part on if I press the turn keys I also turn on the Z axis doing a barrelroll. If I disable one of the 2 parts it works great. How can I fix it that they work together?

    void Update()
    {
        handleKeyboard();
        handleMouse();
        HandleAnimation();
    }

    private void handleKeyboard()
    {
        float z = Input.GetAxisRaw("Horizontal");
        float x = Input.GetAxisRaw("Vertical");
        _move = transform.forward * x;
        _move.Normalize();
        _controller.Move(_move * (Time.deltaTime * playerSpeed));
        _controller.Move(playerVelocity * Time.deltaTime);
        
        if (x == -1)
        {
            transform.Rotate(Vector3.up * (z * -turnSpeed * Time.deltaTime));
        }
        else
        {
            transform.Rotate(Vector3.up * (z * turnSpeed * Time.deltaTime));
        }
    }

    private void handleMouse()
    {
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
        transform.Rotate(Vector3.left * mouseY);
    }

1 Answer

1

You can simply check the mouse is used or not.

if(x == -1 && mouseY == 0)
//Do the stuff

But I want to keep the ability to turn when panning. If I implement this I won't be able to do both at the same time.