Mouse delta problem

I’ve been working on this seemingly easy problem for a while and I’m stumped. I think I’ve narrowed it down to the following code (ran in a new project).

I’m trying to clamp the mouse delta but get different sensitivities in editor and build.

Works (no sensitivity change):

function Update () {
mouse = Input.GetAxisRaw("Mouse X");
transform.Translate(mouse,0,0);
}

Doesn’t work:

function Update () {
mouse = Input.GetAxisRaw("Mouse X");
mouse2 = Mathf.Clamp(mouse,-.3,.3);
transform.Translate(mouse2,0,0);
}

I’d really like to have my editor play equal my build play. Could it be my mouse drivers? Can anyone explain or offer advice please?

What do you mean by “works” and “doesn’t work” in your post above?

I’m referring to “doesn’t work” as in build play mouse delta sensitivity is about 2 or 3 times higher than in editor play. As if there is a hidden multiplier. Can’t figure it out. I really need to clamp the mouse delta.

Sorry but I’m just not sure about any specific mouse sensitivity differences between the editor and the run-time, it “should” (operative word :stuck_out_tongue: ) be the same as it’s the same player in use in both cases.

Perhaps someone else can chime in with their experiences here?

Couple updates.

I have tried windows xp default mouse drivers (from logitech) and it didn’t help.

I also tried a web build and it fixed it.

Lowering the frame rate changed the mouse sensitivity in the build as long as it was lower than about 50. This is not a good work around, I think, because the slower the frame rate the slower the mouse when it is set to a constant speed. I don’t think that’s supposed to happen since Input.GetAxisRaw(“Mouse X”) is a frame rate independent value.

Not foolproof. See Below.

For anyone wanting to work around this I found a way. I’m still pretty new to Unity but this might help.

You can set Application.targetFrameRate to something like 100. This is to get rid of math inaccuracies from high-very high framerates.

Then you can add the code below in FixedUpdate.

mouse = Mathf.Clamp (Input.GetAxis ("Mouse X"), -250,250);
transform.Translate(mouse * sensitivity * Time.deltaTime,0,0);

This will make the mouse movement frame rate independant again after a clamp.

Not foolproof. See Below.

I was wrong on my last two posts about finding workarounds but I think I got it this time. :roll:

For anyone that wants to know:

The clamp throws off the float from Input.GetAxis (“Mouse X”) because it normally varies depending on the frame rate.

But if you do something like below I think it should make it all frame rate independent.

In Update:

transform.Translate(mouse3/21,0,0);
mouse3 = 0;

In FixedUpdate:

mouse = Input.GetAxisRaw("Mouse X");
mouse2 = Mathf.Clamp(mouse, -25, 25);
mouse3 += mouse2;

NOTE: you also have to make sure your build is under a certain frame rate because of math inaccuracies.

If framerate independence is your goal, why aren’t you scaling anything by Time.deltaTime?

Mouse delta samples in unity are an exception to the Time.deltaTime rule.

If you add a Time.deltaTime multiplier it will actually make it framerate dependant (or somewhat so).

Yes I’ve been stuck here as well within FixedUpdate. I have a plane which rolls (AddTorque) based on Input.GetAxis(“Mouse X”). In the editor and web player I have it as desired, but once you use it in a build or web player full screen - everything is different.

The sensitivity suddenly becomes much less. I’ve tried with both multiplying with Time.deltaTime and without. It’s almost as though the delta suddenly changes when you’re in a build - though I don’t see how that can be the case.

All I know is I’ve done a test by adding or subtracting a float whenever the mouse x moves right or left. In the editor it’s fine, but once i’m in a build the increment is much less. Why is this? I’m using Time.deltaTime but the editor and build’s increment is drastically different.

I’m getting this exact same problem. It’s only with the mouse input, but it’s radically different between the editor and the standalone, the standalone is incredibly sluggish, maybe a quarter the speed I get in the editor.

Script is this :

Whether I multiply MouseX by time delta or not, the yaw/pitch is very different from the editor to the standalone.

It’s related to the window size. As I change window resolutions the mouse sensitivity is changing, the total angle of pitch I get from moving my mouse the entire (including the bits outside the game window) vertical distance of my monitor changes with game resolution.

I have a wide screen monitor, if that helps.