4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
9.01k stars 786 forks source link

Add an action to request permission to device sensors on iPhones #4463

Open tristanbob opened 1 year ago

tristanbob commented 1 year ago

Description

The existing device sensor conditions and actions do not work on iPhones running new versions of IOS (13+).

Solution suggested

Background

How to request permission for devicemotion and deviceorientation events in iOS 13+ https://dev.to/li/how-to-requestpermission-for-devicemotion-and-deviceorientation-events-in-ios-13-46g2

How to Request Device Motion and Orientation Permission in iOS 13 https://leemartin.dev/how-to-request-device-motion-and-orientation-permission-in-ios-13-74fc9d6cd140

Working example

This example worked on my iPhone 12 running IOS 15, in both Chrome 107 and Safari. https://kongmunist.medium.com/accessing-the-iphone-accelerometer-with-javascript-in-ios-14-and-13-e146d18bb175

AlexandreSi commented 1 year ago

Hi @tristanbob and thank you for taking the time to look into solutions for this! The solution you found seems to be supported by Safari on iOs only (https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent#browser_compatibility) CanIUse is more optimistic though: https://caniuse.com/?search=requestPermission

I wonder if this issue occurs on Android smartphones as well. Do you have a game example that I could use to test on my Android?

tristanbob commented 1 year ago

@AlexandreSi there are a couple game examples already inside GDevelop that you can test with. Search for "device sensor".

The external example I linked to worked on my Safari and Chrome browser, so it feels like it should work for most users.

tristanbob commented 1 year ago

Any updates on this? I'd love to make games with this feature.

https://x.com/victrisgames/status/1697456638477881651?s=46&t=ez41cYT0tq4QuAag1Dbrcg

tristanbob commented 5 months ago

I found the source to website that does a good job with this:

https://aframe.io/examples/

Source:

https://github.com/aframevr/aframe/blob/master/src/components/scene/device-orientation-permission-ui.js