var MOTOR_WALK = 5.0; var MOTOR_JOG = 2.0; var MOTOR_RUN = 10.0; var MOTOR_JUMP = 2.0; var IMPULSE_JUMP = 100; var MOTOR_INPUT_RUN_LIMIT = 0.985; var MOTOR_INPUT_JOG_LIMIT = 0.6; var MOTOR_INPUT_WALK_LIMIT = 0.15; const MAX_REVERSE_SPEED = -2; var force = 8; var dir = 0; var air = 0.5; var vel = {x: 0, y: 0, z: 0}; var vehicleYaw = 40; var defaultYaw = 0; var MOTOR_TIMESCALE = 1.0; var MOTOR_TIMESCALE_MAX = 1000000.0; var MOTOR_TIMESCALE_MULTIPLIER = 2.5; var MOTOR_VECTOR_ZERO = {x: 0, y: 0, z: 0}; var motorVector = MOTOR_VECTOR_ZERO; MyAvatar.motorReferenceFrame = "camera"; var fwd = false; var back = false; var shift = false; var motorActive = false; var isActive = true; var Vive = Controller.Hardware.Vive; var controllerMapping; var controllerMappingName; var ROOT = "http://mpassets.highfidelity.com/0df3dbd8-42b7-4c7c-8637-58ef10bb05db-v1/"; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var icon = ROOT + "floofSprint_off.svg"; var activeIcon = ROOT + "floofSprint_on.svg"; var activeButton = tablet.addButton({ icon: icon, activeIcon: activeIcon, text: "TEST VEHICLE", isActive: true, sortOrder: 0 }); Script.scriptEnding.connect(function () { tablet.removeButton(activeButton); }); var toggle = function () { isActive = !isActive; activeButton.editProperties({isActive: isActive}); if (isActive) { Controller.enableMapping(controllerMappingName); defaultYaw = MyAvatar.yawSpeed; MyAvatar.yawSpeed = vehicleYaw; } else { Controller.disableMapping(controllerMappingName); MyAvatar.yawSpeed = defaultYaw; motorActive = true; } }; Script.scriptEnding.connect(function () { Controller.disableMapping(controllerMappingName); }); activeButton.clicked.connect(toggle); controllerMappingName = 'Hifi-TestMotion-Mapping'; controllerMapping = Controller.newMapping(controllerMappingName); function empty(val) { } controllerMapping.from(Controller.Hardware.Keyboard.W).to(function (value) { if (value != 0) { MyAvatar.motorReferenceFrame = "avatar"; fwd = true; if (shift) { dir = 1; } else { dir = 1; } } else { fwd = false; dir = 0; } }); controllerMapping.from(Controller.Hardware.OculusTouch.LX).to(function (value) { // disable strafe since that's not vehicularly normal }); controllerMapping.from(Controller.Hardware.OculusTouch.RY).to(function (value) { // disable jump since that's not vehicularly normal }); controllerMapping.from(Controller.Hardware.OculusTouch.LY).to(function (value) { var d = new Date(); stickDownLastTime = d.getTime(); if (value > 0.1) {fwd = true; back = false;} if (value < -0.1) {back = true; fwd = false;} if (back) { MyAvatar.motorReferenceFrame = "avatar"; dir = -1; } else if (fwd) { MyAvatar.motorReferenceFrame = "avatar"; dir = 1; } else { fwd = false; back = false; dir = 0; } }); controllerMapping.from(Controller.Hardware.Keyboard.S).to(function (value) { if (value != 0) { MyAvatar.motorReferenceFrame = "avatar"; back = true; if (shift) { dir = -0.1; } else { dir = -0.1; } } else { back = false; dir = 0; } }); var frameCount = 0; var stickInUse = false; var STICKUP_DELAY = 500; var stickDownLastTime; function timeFunction(deltaTime) { MyAvatar.motorTimescale = MOTOR_TIMESCALE; MyAvatar.hmdLeanRecenterEnabled = false; // dont turn the vehicle when the avatar turns its head if (!fwd && !back) dir = 0; var d = new Date(); var currentTime = d.getTime(); var timeDiff = currentTime - stickDownLastTime; if ( timeDiff > STICKUP_DELAY) { dir = 0; // it's been longer than back = false; fwd = false; } //print("VEHICLE: "+timeDiff); if (vel.z < -3) vel.z = MAX_REVERSE_SPEED;//0.8; //brakes vel = { x: vel.x, y: vel.y, z: (vel.z + (dir * force * deltaTime)) * (Math.pow(air, deltaTime)) }; MyAvatar.motorVelocity = { x: MyAvatar.motorVelocity.x, y: MyAvatar.motorVelocity.y, z: vel.z }; frameCount = (frameCount + 1) % 50; if (frameCount === 0) { // print(deltaTime); // print(vel.z); // print(dir); // print((dir * force * deltaTime)); // print((1 - Math.pow(air, deltaTime))); // print((vel.z + (dir * force * deltaTime)) * (1 - Math.pow(air, deltaTime))); } } defaultYaw = MyAvatar.yawSpeed; MyAvatar.yawSpeed = vehicleYaw; Controller.enableMapping(controllerMappingName); Script.scriptEnding.connect(function () { Controller.disableMapping(controllerMappingName); }); Script.scriptEnding.connect(function () { MyAvatar.yawSpeed = defaultYaw; Script.update.disconnect(timeFunction); activeButton.clicked.disconnect(toggle); tablet.removeButton(activeButton); Controller.disableMapping(controllerMappingName); }); Script.update.connect(timeFunction);