Add facing threshold

This commit is contained in:
Eric Rosenbaum 2019-01-29 17:09:11 -05:00
parent 4449ee7f0f
commit 6cbc71f8d1

View file

@ -43,6 +43,12 @@ const MOVED_THRESHOLD = 3;
*/ */
const SHAKEN_THRESHOLD = 30; const SHAKEN_THRESHOLD = 30;
/**
* Threshold for acceleration magnitude, to check if we are facing up.
* @type {number}
*/
const FACING_THRESHOLD = 9;
/** /**
* Acceleration due to gravity, in m/s^2. * Acceleration due to gravity, in m/s^2.
* @type {number} * @type {number}
@ -754,9 +760,9 @@ class Scratch3GdxForBlocks {
isFacing (args) { isFacing (args) {
switch (args.FACING) { switch (args.FACING) {
case FaceValues.UP: case FaceValues.UP:
return this._peripheral.getAccelerationZ() > GRAVITY; return this._peripheral.getAccelerationZ() > FACING_THRESHOLD;
case FaceValues.DOWN: case FaceValues.DOWN:
return this._peripheral.getAccelerationZ() < GRAVITY * -1; return this._peripheral.getAccelerationZ() < FACING_THRESHOLD * -1;
default: default:
log.warn(`Unknown direction in isFacing: ${args.FACING}`); log.warn(`Unknown direction in isFacing: ${args.FACING}`);
} }