p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Mobile Acceleration examples not working.

Open RichardDL99 opened this issue 3 years ago • 2 comments
trafficstars

Example ex00_Acceleration_Ball_Bounce used to work in 2018 but doesn't now. I tried it on 2 phones today. (Android 6.0.1, Android 10). I made a small program just showing the AccelerationX,Y,Z values - always zero. I guess the code hasn't changed so the problem is security on the phone. I've tried giving Chrome all the permissions available - no better. ex03_Shake_Ball_Bounce the same.

This was a great feature, I've seen 20 10-year-olds all shake their phones with this and laugh. Shame it doesn't work now.

function setup() {
  createCanvas(displayWidth, displayHeight);
  fill(0);}

function draw() {
  background(255);
  textSize(36);
  textAlign(RIGHT);
  text(frameCount   , 250,  40);
  text(accelerationX, 250,  80);
  text(accelerationY, 250, 110);
  text(accelerationZ, 250, 140);}

RichardDL99 avatar Dec 01 '21 12:12 RichardDL99

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

welcome[bot] avatar Dec 01 '21 12:12 welcome[bot]

Probably related to some permission request API. I haven't got time to look into this but I plan to have a look at this eventually if someone else didn't get to this first.

limzykenneth avatar Dec 04 '21 17:12 limzykenneth

Please, please, please...

RichardDL99 avatar Apr 30 '23 19:04 RichardDL99

Any solutions? This bug seems to still be valid.

CyberedCake avatar Aug 21 '23 16:08 CyberedCake

Does anything set an event listener with this any more? https://github.com/processing/p5.js/blob/ad5c51a73080463804caac604a0cf2181c0274c8/src/events/acceleration.js#L632-L638

From a quick search I couldn't see it getting set up, maybe that's why?

davepagurek avatar Aug 21 '23 18:08 davepagurek

Sorry this took sooooo long. The problem is as I originally suspected a permission issue. DeviceOrientationEvent.requestPermission() and/or DeviceMotionEvent.requestPermission() need to be called before we can access the relevant acceleration and rotation values. As a temporary fix for the users, include the above functions in a mouse click event should enable it (it will pop up a permission request for your users), it may give an error on Android devices so it may need to be checked for existence before hand (don't have an Android device to test myself).

On our end the fix is potentially much more complicated unless we can make accelerationX/YZ etc getters, as we register the event listeners on initialisation, so if we add the requests there it will pop up the request regardless of whether the user is using acceleration features or not in iOS.

One thing I think was suggested before (don't remember where exactly) is to create a utility function for general requests in one function, although it might be better to include the note about the request functions required in the documentation directly.

limzykenneth avatar Sep 26 '23 15:09 limzykenneth