Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Nice, didn't expect golf. There's a weird glitch with the mouse capture where the view constantly rotates slowly right.

(2 edits)

Huh, that mouse capture issue is weird. It was a last-minute addition because I'd been capturing the mouse on start-up while testing on desktop, but then I learned mouse capture has to be handled differently for HTML5 (see 'Full screen and mouse capture' here). Essentially, you cannot just capture the mouse whenever you like, but instead it has to happen in response to an input event, e.g. a click. So I now have the following code:

public override void _UnhandledInput(InputEvent @event)
{
  var click = @event as InputEventMouseButton;
  if (click != null)
  {
    Input.SetMouseMode(Input.MouseMode.Captured);
  }
  
  var e = @event as InputEventMouseMotion;
  if (e == null)
    return;
  
  RotateY(-e.Relative.x * turnSpeed);
  
  float deltaPitch = -e.Relative.y * turnSpeed;
  if (_pitch + deltaPitch > 1.5f || _pitch + deltaPitch < -1.5f)
    return;
  
  _pitch += deltaPitch;
  _camera.RotateX(deltaPitch);
}

My last-minute change was adding the first 5 lines inside this function i.e. relating to `var click` and `SetMouseMode`. It works fine on desktop and I cannot see a reason why this change should cause issues with slowly drifting rotation.

After your post I tested it for myself but in my case the view slowly rotates downwards (instead of to the right as you found) - but only when the mouse is captured and only intermittently.

If anyone has an explanation for why there's an inconsistent rotational drift but only in HTML5 and only after capturing the mouse, then I'd love to hear it!

Thanks for the review by the way! :)