Gyroscope and Accelerometer ⭐ sensors on WebGL using itch.io or CrazyGames

Hi, what I need to do to make the Gyroscope/Accelerometer work on the publishing platforms?

I created a Sensor Camera (Unity Asset) that works via local Wi-Fi testing with HTTPS self-signed cert as it shown here.

  • But one of my clients says that it doesn’t work when uploading a Unity WebGL build on the itch.io.
  • On my turn, I tested it on CrazyGames portal and the situation was the same: there is no data from sensors.

Devs, do you have any tips?

2 Likes

I came across your question due to the AI generated spam answer :slight_smile:
There’s something not really clear about your sensor camera thing. Where exactly does your server run and how exactly is that related to WebGL? First of all you should know that a WebGL project is completely incapable to actually run a server locally. Websites can not create listen sockets and access to other domains are heavily restricted. Your “server” would need to run natively on some device and when you want to connect to it from a WebGL build (which would be quite weird), the server would need to implement proper CORS headers to allow cross origin requests. Though some browsers generally block connections to localhost because in most cases that would be a huge security issue.

When you build your game as a WebGL project and upload it to an external hoster like itch, that hoster is the “home” domain of the website. Accessing any other server that runs under and other domain would require that server to provide CORS and either specifically allow that one domain, or allow all domains to access the server.

Though as I said, when you plan on running that WebGL game inside a mobile browser, you can not start a local server inside the browser. That just doesn’t work at all under no circumstances.

As I said, I haven’t really looked into that sensor camera thing and who or where that server is started, but if your goal was to use this in a WebGL build, that’s just not possible.

WebGL / Javascript in a browser does get limited access to certain sensory information via browser interfaces in javascript. I’m currently not up to date what Unity actually supports on WebGL platforms. However mobile browsers are generally quite limited when it comes to running WebGL content.

I don’t know why you use a local webserver for this. I mean it would make somewhat sense if you created something like the Unity Remote app which does provide the mobile sensory data to an external application. Though the exact usecase it not clear, at least to me. Maybe you could clarify how this is supposed to work.

I guess there is some misunderstanding. I attached the link that shows in the 1st post what I am doing.

Here is the direct video demo of testing my asset. I am using a local web server just for test. Asset doesn’t contain web server, cross-domain requests, and any web-requests at all.

It just uses data from Motion Sensors from both Unity Input Systems: Old and New, where it needs.

1 Like

Yes, it seems there is :slight_smile: So when we just talk about a plain WebGL build, then yes, it should actually work. However WebGL on mobile browsers isn’t officially supported by Unity as those browsers have limited and sometimes no or bad support for certain advanced web standards. It’s getting better as time goes on though.

There has been some threads about issues with mobile sensory input on mobile devices in the past and you even replied to them.

Someone has mentioned that specifically on itch there seems to be something special in the way they initialize the Unity player and how they wrap it in the DOM which may cause issues. Not sure how well the support for such things is in an “iframe” for example. It’s difficult to narrow it down. Since some have mentioned that even native javascript calls fail in those cases, I don’t think that there’s much you can do about that. Though I have never released anything on itch io, so I can only repeat what I’ve heard.

Since the issue may be related to a specific device / OS / browser as well as the specifics about how the WebGL content may be wrapped, it’s difficult to test all those cases (unless you have many different testing devices). If the issue only exists on certain hosters, it may be worth to try to replicate their loading and wrapping scheme in order to reproduce the issue.

Sorry I can’t really help any further here. Maybe someone else has made some more recent experiments regarding WebGL content in mobile browsers.

1 Like

Solutions

  1. Solution for itch.io from my client:

Plugin doesn’t work as an iFrame, so what I did was just use the actual url instead of the embedded version on itch. It is running on itch url that contains the execution, but not in the embedded test window.


  1. CrazyGames:
  • Sensors works from the box on Android.
  • For the iOS case, I contacted the support with a bug report.
1 Like