mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Factor out and scale spin speed
This commit is contained in:
parent
1abbf55f55
commit
b5fb80190d
1 changed files with 14 additions and 12 deletions
|
@ -318,24 +318,26 @@ class GdxFor {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpinSpeedX () {
|
getSpinSpeedX () {
|
||||||
if (this._canReadSensors()) {
|
return this._getSpinSpeed(5);
|
||||||
return this._device.getSensor(5).value * (180 / Math.PI);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpinSpeedY () {
|
getSpinSpeedY () {
|
||||||
if (this._canReadSensors()) {
|
return this._getSpinSpeed(6);
|
||||||
return this._device.getSensor(6).value * (180 / Math.PI);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpinSpeedZ () {
|
getSpinSpeedZ () {
|
||||||
if (this._canReadSensors()) {
|
return this._getSpinSpeed(7);
|
||||||
return this._device.getSensor(7).value * (180 / Math.PI);
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
_getSpinSpeed (sensorNum) {
|
||||||
|
if (!this._canReadSensors()) return 0;
|
||||||
|
let val = this._device.getSensor(sensorNum).value;
|
||||||
|
val = MathUtil.radToDeg(val);
|
||||||
|
const framesPerSec = 1000 / this._runtime.currentStepTime;
|
||||||
|
val = val / framesPerSec; // convert to from degrees per sec to degrees per frame
|
||||||
|
val = Math.round(val);
|
||||||
|
val = val * -1;
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue