66 lines
No EOL
1.8 KiB
JavaScript
66 lines
No EOL
1.8 KiB
JavaScript
/*
|
|
Analog Movement Script
|
|
|
|
Written by r3tk0n
|
|
10/02/2018
|
|
*/
|
|
|
|
(function () { // BEGIN LOCAL SCOPE
|
|
var mappingName, ctrlrMapping;
|
|
var LX = 0, LY = 0, RX = 0, RY = 0;
|
|
var maxSpeed = 4.5;
|
|
var timeScale = 1000;
|
|
|
|
function update (delta) {
|
|
var forward = Vec3.multiply((LY * maxSpeed), Vec3.FRONT);
|
|
var side = Vec3.multiply((LX * maxSpeed), Vec3.UNIT_X);
|
|
var velocity = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.sum(forward, side));
|
|
MyAvatar.motorVelocity = velocity;
|
|
MyAvatar.motorTimescale = delta;
|
|
}
|
|
|
|
function cleanup () {
|
|
print("Killing analog movement script...");
|
|
MyAvatar.velocity = Vec3.ZERO; // Default value.
|
|
MyAvatar.motorTimescale = 1000000; // Default value.
|
|
MyAvatar.motorReferenceFrame = "camera";// Default value.
|
|
MyAvatar.motorMode = "simple";
|
|
Script.update.disconnect(update);
|
|
Controller.disableMapping(mappingName);
|
|
}
|
|
|
|
function setup () {
|
|
mappingName = "HiFi-Analog-Movement-Dev-" + Math.random();
|
|
ctrlrMapping = Controller.newMapping(mappingName);
|
|
if (Controller.Hardware.OculusTouch) {
|
|
ctrlrMapping.from(Controller.Hardware.OculusTouch.LX).to(getLX);
|
|
ctrlrMapping.from(Controller.Hardware.OculusTouch.LY).to(getLY);
|
|
} else if (Controller.Hardware.Vive) {
|
|
ctrlrMapping.from(Controller.Hardware.Vive.LX).to(getLX);
|
|
ctrlrMapping.from(Controller.Hardware.Vive.LY).to(getLY);
|
|
} else {
|
|
// Do nothing.
|
|
}
|
|
|
|
Controller.enableMapping(mappingName);
|
|
MyAvatar.motorTimescale = timeScale; // in microseconds
|
|
MyAvatar.motorMode = "simple";
|
|
MyAvatar.motorReferenceFrame = "world";
|
|
|
|
print("Analog movement bindings set up...");
|
|
}
|
|
|
|
function getLX (value) {
|
|
LX = value;
|
|
}
|
|
|
|
function getLY (value) {
|
|
LY = value;
|
|
}
|
|
|
|
setup();
|
|
|
|
Script.update.connect(update);
|
|
|
|
Script.scriptEnding.connect(cleanup);
|
|
}()); // END LOCAL SCOPE
|