Mouse sensitivity in WebGL - WAY too sensitive

To anyone stumbling on this post, remistorms’ answer was close to the desired effect, but I found it dampened large motions too much. Here’s what I did instead:

var x = Input.GetAxisRaw ("Mouse X");
var y = Input.GetAxisRaw ("Mouse Y");
if (Application.platform == RuntimePlatform.WebGLPlayer) {
  x = MouseLook.DampenedMovement (x);
  y = MouseLook.DampenedMovement (y);
}
x *= sensitivity; // your custom sensitivity value...
y *= sensitivity; // ...which may be user-adjustable

// define this function:
public static float DampenedMovement (float value) {

  if (Mathf.Abs (value) > 1f) {
    // best value for dampenMouse is 0.5 but better make it user-adjustable
    return Mathf.Lerp (value, Mathf.Sign (value), dampenMouse);
  }
  return value;
}

Also note: sensitivity seems to vary by browser/OS. I only tested on Edge/Firefox/Chrome on Windows 10, and found that I had to multiply the original (standalone) sensitivity by 0.25 for Chrome and Edge, and about 0.5 for Firefox, to make it feel similar to standalone. Try to find a good default value and make it user-adjustable.

2 Likes

Hello everyone!

I was having the same issue, and the workaround that I found was this:

0.- To try the understand the problema, I did the follow excercise.

1.- Make a new project.
2.- Download Stantard FPS of Unity, Cinemachine and New Input System
3.- Create a new scene with a nested fps prefab.
4.- Create a floor and some props.
5.- Buils for HTML 5.
6.- Upload to your server or itch.io

The result is that, the DEFAULT value of FPS SCRIPT for the FPS prefab is too LARGE or HIGH for HTML.

Tha value is the mouse delta for the rotation of the player.

I set the same proyect but with values from 0.5 to 1.0 and the problem was controlled.

Hope you guys can make a better solution for Unity and HTML. We need that HTML export can respect the values on editor.

Cheers.

This more or less did the trick for me as well!

You can also get delta’s from the browser. Maybe it’s too performance heavy but I wonder if it’s possible to send the browser delta to Unity WebGL.

function logMovement(event) {
  log.innerText = `movement: ${event.movementX}, ${event.movementY}\n${log.innerText}`;
}

const log = document.getElementById('log');
document.addEventListener('mousemove', logMovement);

Still, it’s pretty crazy this issue is 6 years old and still hasn’t been fixed.

4 Likes

macOS Ventura, M2 chip, it is faster in Chrome or Safari than in Editor and Standalone macOS build.

The solution in this thread doesn’t work for me properly. It is still faster in browsers.

I use this method in LateUpdate (going to use this in my basketball asset):

        horizontalDelta = Input.GetAxis(horizontalAxis);
        verticalDelta = Input.GetAxis(verticalAxis);

#if UNITY_WEBGL && !UNITY_EDITOR

        horizontalDelta /= 10f;
        verticalDelta /= 10f;

#endif

oof my WebGL build cursor sensitivity is way more than how it is set in the Editor. That’s a big problem

Same problem, not sure if relevant but this extends to anything with a mouse scroll wheel input as well, where the sensitivity is waaaaaay over 2 times of what it would be in the unity editor

WebGL mouse sensitivity is extremly low here on Safari. How can I fix that?

bumping this again, please provide a solution, or at least a workaround

We have this problem with one of our team but not me. Me: Windows, Chrome, Edge browser. Mousewheel motion is the same as in editor. My team-mate, also on Windows, also using Chrome, the mousewheel is crazy fast in the game.
(Unity 2021.3.32)

The problem seems to be with ‘Mouse acceleration’ settings, that is used more by Mac users.
In Windows this setting can also be enabled but is called ‘Enhance pointer precision’.
Enabling this acceleration causes scrolling in WebGL builds to be crazy fast, disabling it ‘fixes’ the problem:

It would be nice if this setting can be ignored / detected in Unity.

Hmmm, why it affects WebGL only?

Unity just have to add it …

https://discussions.unity.com/t/917666

1 Like

Our workaround was to provide the player with mouse sensitivity settings they can modify in game.