Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Last active November 7, 2020 20:03
Show Gist options
  • Save Utopiah/fdfa7a2d6967a2178a3bd0f284dc3c12 to your computer and use it in GitHub Desktop.
Save Utopiah/fdfa7a2d6967a2178a3bd0f284dc3c12 to your computer and use it in GitHub Desktop.
if (typeof Puck === "undefined") throw "Load http://www.puck-js.com/puck.js first"
Puck.write("var data;\nThingy.onMPU(r=>data=r);\n");
// making latest MPU data accessible on device, namely gyo + accel + ...
var data = {x:0, y:0, z:0}
var threshold = 25
var speed = 1
var pos = document.querySelector("#avatar-rig").object3D.position;
var rotationCam = document.querySelector("#avatar-pov-node").object3D.rotation;
function actionWhenActive(){
pos.x += speed * Math.cos( rotationCam.y );
pos.z -= speed * Math.sin( rotationCam.y );
}
var refresh = setInterval( _ => { Puck.eval("data.gyro", res => data = res );
if ( data && data.x*data.x > threshold || data.y*data.y > threshold || data.z*data.z > threshold) actionWhenActive()
}, 100 )
// Warning : works only on Chromium due to WebBT being required. Consequently problematic on Quest.
// could make the data available as an endpoint then pull on Quest and act based on that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment