3D solution to rotate a ship continually without dragging the mouse?

Right now I have a very basic script to turn a ship in space.

float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(-v, h, 0);

With this you have to continually “drag” the mouse to keep turning.

I am researching solutions to go from no rotation while the cursor is inside a specific tiny area at the center of the screen to rotating closer and closer to its maximum rotation speed as it reaches the edge of an invisible box (see the box in the image below). Then the cursor will be clamped to not leave the edges of that imaginary box.

Just looking to be pointed in the right direction.

tried something simple like this?

float h += horizontalSpeed * Input.GetAxis("Mouse X");
float v += verticalSpeed * Input.GetAxis("Mouse Y");
if(v > 1f || h > 1f || v < -1f || h < -1f)
    transform.Rotate(-v, h, 0);

edit: for your center deadspace you could do something like the if statement

well… is it really necessary to lock the mouse in that boundary?

could you perhaps just check if the mouse is in that boundary and do a quick % based on it’s relative position to the boundary position (and adjust speed accordingly)?

if the mouse was outside the boundary, there would be no additional change in rotation… causing a continuous rotation.

if the mouse was inside the boundary, change accordingly.

Yea, I don’t have to, I just kind of thought of it additionally as a solution for people with multiple monitors or windowed games to keep it inside while flying. Then maybe press ALT to release it from the clamped area. Assuming that would even work. :stuck_out_tongue:

Also if I did it there would be a custom cursor (that I have in now) that lets you keep an eye on which way you’re turning. It would just stay in a area around the center of the screen instead of going all over the screen. Just seemed like a possibly helpful feature. Maybe not. Won’t know until I try it. :slight_smile:

Got some odd behavior from that.

Edit: I did find two ways to do what I was aiming for, but neither one are accurate ways to control the ship and shoot/aim. The code is just to test the idea to see if it could actually work with some changes.

One is this which creates a kind of dead zone in the center so you can actually stop turning:

// **************************** NEW SYSTEM WIP - TESTING ************************
        if (Input.mousePosition.y <= 200) { transform.Rotate(verticalSpeed, 0, 0); }
        if (Input.mousePosition.y >= 450) { transform.Rotate(-verticalSpeed, 0, 0); }

        if (Input.mousePosition.x <= 450) { transform.Rotate(0, -horizontalSpeed, 0); }
        if (Input.mousePosition.x >= 850) { transform.Rotate(0, horizontalSpeed, 0); }

Then this, which has no dead zone, but you can’t stop turning and it behaves inaccurately for turning:

/**************************** TESTING THIS METHOD *****************************
        int centerX = (Screen.width / 2);
        int centerY = (Screen.height / 2);

        if (Input.mousePosition.y < centerY) { transform.Rotate(verticalSpeed, 0, 0); }
        if (Input.mousePosition.y > centerY) { transform.Rotate(-verticalSpeed, 0, 0); }

        if (Input.mousePosition.x < centerX) { transform.Rotate(0, -horizontalSpeed, 0); }
        if (Input.mousePosition.x > centerX) { transform.Rotate(0, horizontalSpeed, 0); }
        */