685 lines
19 KiB
JavaScript
Raw Normal View History

// Created by james b. pollack @imgntn on 7/2/2016
// Copyright 2016 High Fidelity, Inc.
//
// Creates a beam and target and then teleports you there when you let go of the activation button.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
2016-07-01 17:26:52 -07:00
//FEATURES:
2016-07-05 17:48:30 -07:00
// ENTRY MODES
// Thumbpad only
// Thumpad + trigger
2016-07-06 13:20:42 -07:00
// JUMP MODES
// Instant
// Smoth arrival aka stepwise (number of steps, duration of step)
// FADE MODE
// Cube-overlay (steps,duration)
// Model-overlay (steps, duration)
// Fade out / fade in
// defaults with instant jump with fade. to try smooth arrival mode, change use fade to false and then switch the number of arrival steps and spacing
2016-06-30 16:05:44 -07:00
var inTeleportMode = false;
2016-06-29 15:59:51 -07:00
2016-07-05 10:31:47 -07:00
var currentFadeSphereOpacity = 1;
var fadeSphereInterval = null;
2016-07-07 14:37:51 -07:00
var fadeSphereUpdateInterval = null;
//milliseconds between fading one-tenth -- so this is a half second fade total
2016-07-07 14:37:51 -07:00
var USE_FADE_MODE = true;
var USE_FADE_IN = false;
var USE_FADE_OUT = true;
var FADE_IN_INTERVAL = 25;
var FADE_OUT_INTERVAL = 25;
2016-07-07 11:42:41 -07:00
// instant
var NUMBER_OF_STEPS = 0;
var SMOOTH_ARRIVAL_SPACING = 0;
// // slow
// var SMOOTH_ARRIVAL_SPACING = 150;
// var NUMBER_OF_STEPS = 2;
2016-07-06 17:52:18 -07:00
2016-07-07 14:37:51 -07:00
// medium-slow
2016-07-06 18:13:42 -07:00
// var SMOOTH_ARRIVAL_SPACING = 100;
// var NUMBER_OF_STEPS = 4;
2016-07-06 17:52:18 -07:00
//medium-fast
2016-07-06 18:13:42 -07:00
// var SMOOTH_ARRIVAL_SPACING = 33;
// var NUMBER_OF_STEPS = 6;
2016-07-06 17:52:18 -07:00
2016-07-07 14:37:51 -07:00
//fast
2016-07-06 18:13:42 -07:00
// var SMOOTH_ARRIVAL_SPACING = 10;
// var NUMBER_OF_STEPS = 20;
2016-07-06 17:52:18 -07:00
2016-07-07 14:37:51 -07:00
var USE_THUMB_AND_TRIGGER_MODE = true;
2016-07-07 12:39:11 -07:00
2016-07-07 12:52:24 -07:00
var TARGET_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/teleporter/target.fbx';
2016-07-01 15:19:37 -07:00
var TARGET_MODEL_DIMENSIONS = {
2016-07-01 17:26:52 -07:00
x: 1.15,
2016-07-05 09:22:19 -07:00
y: 0.5,
2016-07-01 17:26:52 -07:00
z: 1.15
2016-07-01 15:19:37 -07:00
2016-07-06 13:20:42 -07:00
};
2016-06-30 16:05:44 -07:00
function ThumbPad(hand) {
this.hand = hand;
var _this = this;
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
this.buttonPress = function(value) {
_this.buttonValue = value;
};
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
this.down = function() {
return _this.buttonValue === 1 ? 1.0 : 0.0;
};
}
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
function Trigger(hand) {
this.hand = hand;
var _this = this;
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
this.buttonPress = function(value) {
_this.buttonValue = value;
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
};
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
this.down = function() {
return _this.buttonValue === 1 ? 1.0 : 0.0;
};
2016-06-29 15:59:51 -07:00
}
2016-06-30 16:05:44 -07:00
function Teleporter() {
var _this = this;
this.intersection = null;
2016-06-30 16:05:44 -07:00
this.targetProps = null;
2016-07-06 15:16:31 -07:00
this.rightOverlayLine = null;
this.leftOverlayLine = null;
this.targetOverlay = null;
this.updateConnected = null;
2016-07-07 11:42:41 -07:00
this.smoothArrivalInterval = null;
2016-07-07 14:37:51 -07:00
this.fadeSphere = null;
this.teleportHand = null;
2016-06-30 16:05:44 -07:00
this.initialize = function() {
this.createMappings();
this.disableGrab();
};
2016-07-01 15:19:37 -07:00
this.createTargetOverlay = function() {
2016-07-01 15:19:37 -07:00
var targetOverlayProps = {
url: TARGET_MODEL_URL,
dimensions: TARGET_MODEL_DIMENSIONS,
visible: true,
2016-07-01 15:19:37 -07:00
};
_this.targetOverlay = Overlays.addOverlay("model", targetOverlayProps);
2016-06-30 16:05:44 -07:00
};
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
this.createMappings = function() {
// peek at the trigger and thumbs to store their values
2016-07-01 00:48:29 -07:00
teleporter.telporterMappingInternalName = 'Hifi-Teleporter-Internal-Dev-' + Math.random();
teleporter.teleportMappingInternal = Controller.newMapping(teleporter.telporterMappingInternalName);
2016-06-30 16:05:44 -07:00
Controller.enableMapping(teleporter.telporterMappingInternalName);
};
2016-06-29 18:28:39 -07:00
2016-06-30 16:05:44 -07:00
this.disableMappings = function() {
Controller.disableMapping(teleporter.telporterMappingInternalName);
};
2016-06-29 18:28:39 -07:00
2016-06-30 16:05:44 -07:00
this.enterTeleportMode = function(hand) {
2016-07-08 13:37:59 -07:00
print('entered teleport from ' + hand)
2016-06-30 16:05:44 -07:00
if (inTeleportMode === true) {
2016-07-08 13:37:59 -07:00
print('already in teleport mode so dont enter again')
return;
}
2016-07-07 11:42:41 -07:00
if (this.smoothArrivalInterval !== null) {
Script.clearInterval(this.smoothArrivalInterval);
}
2016-06-30 16:05:44 -07:00
inTeleportMode = true;
this.teleportHand = hand;
this.initialize();
this.updateConnected = true;
2016-07-08 13:37:59 -07:00
Script.update.connect(this.update);
2016-07-01 11:12:20 -07:00
2016-06-30 16:05:44 -07:00
};
2016-06-29 15:59:51 -07:00
2016-07-06 17:52:18 -07:00
this.findMidpoint = function(start, end) {
var xy = Vec3.sum(start, end);
var midpoint = Vec3.multiply(0.5, xy);
return midpoint
};
2016-07-07 14:37:51 -07:00
2016-07-05 10:31:47 -07:00
this.createFadeSphere = function(avatarHead) {
var sphereProps = {
position: avatarHead,
2016-07-07 14:37:51 -07:00
size: -1,
2016-07-05 10:31:47 -07:00
color: {
red: 0,
green: 0,
blue: 0,
},
alpha: 1,
solid: true,
visible: true,
ignoreRayIntersection: true,
2016-07-07 14:37:51 -07:00
drawInFront: false
2016-07-05 10:31:47 -07:00
};
2016-07-07 14:37:51 -07:00
currentFadeSphereOpacity = 10;
_this.fadeSphere = Overlays.addOverlay("sphere", sphereProps);
2016-07-07 14:37:51 -07:00
Script.clearInterval(fadeSphereInterval)
Script.update.connect(_this.updateFadeSphere);
2016-07-07 14:37:51 -07:00
if (USE_FADE_OUT === true) {
this.fadeSphereOut();
}
if (USE_FADE_IN === true) {
this.fadeSphereIn();
}
2016-07-05 10:31:47 -07:00
};
this.fadeSphereOut = function() {
fadeSphereInterval = Script.setInterval(function() {
2016-07-07 14:37:51 -07:00
if (currentFadeSphereOpacity <= 0) {
2016-07-05 10:31:47 -07:00
Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere();
fadeSphereInterval = null;
2016-07-05 10:31:47 -07:00
return;
}
if (currentFadeSphereOpacity > 0) {
2016-07-07 14:37:51 -07:00
currentFadeSphereOpacity = currentFadeSphereOpacity - 1;
2016-07-05 10:31:47 -07:00
}
2016-07-07 14:37:51 -07:00
2016-07-05 10:31:47 -07:00
Overlays.editOverlay(_this.fadeSphere, {
2016-07-07 14:37:51 -07:00
alpha: currentFadeSphereOpacity / 10
2016-07-05 10:31:47 -07:00
})
}, FADE_OUT_INTERVAL);
2016-07-05 10:31:47 -07:00
};
this.fadeSphereIn = function() {
fadeSphereInterval = Script.setInterval(function() {
2016-07-07 14:37:51 -07:00
if (currentFadeSphereOpacity >= 1) {
2016-07-05 10:31:47 -07:00
Script.clearInterval(fadeSphereInterval);
_this.deleteFadeSphere();
2016-07-05 10:31:47 -07:00
fadeSphereInterval = null;
return;
}
if (currentFadeSphereOpacity < 1) {
2016-07-07 14:37:51 -07:00
currentFadeSphereOpacity = currentFadeSphereOpacity - 1;
2016-07-05 10:31:47 -07:00
}
Overlays.editOverlay(_this.fadeSphere, {
2016-07-07 14:37:51 -07:00
alpha: currentFadeSphereOpacity / 10
2016-07-05 10:31:47 -07:00
})
}, FADE_IN_INTERVAL);
};
this.updateFadeSphere = function() {
var headPosition = MyAvatar.getHeadPosition();
Overlays.editOverlay(_this.fadeSphere, {
position: headPosition
})
2016-07-05 10:31:47 -07:00
};
this.deleteFadeSphere = function() {
2016-07-07 14:37:51 -07:00
if (_this.fadeSphere !== null) {
Script.update.disconnect(_this.updateFadeSphere);
Overlays.deleteOverlay(_this.fadeSphere);
_this.fadeSphere = null;
}
2016-07-05 10:31:47 -07:00
};
this.deleteTargetOverlay = function() {
Overlays.deleteOverlay(this.targetOverlay);
this.intersection = null;
this.targetOverlay = null;
}
2016-07-06 15:16:31 -07:00
this.turnOffOverlayBeams = function() {
this.rightOverlayOff();
this.leftOverlayOff();
}
2016-06-30 16:05:44 -07:00
this.exitTeleportMode = function(value) {
2016-07-08 13:37:59 -07:00
print('exiting teleport mode')
2016-07-07 12:39:11 -07:00
2016-07-08 13:37:59 -07:00
Script.update.disconnect(this.update);
this.teleportHand = null;
this.updateConnected = null;
2016-06-30 16:05:44 -07:00
this.disableMappings();
2016-07-06 15:16:31 -07:00
this.turnOffOverlayBeams();
2016-06-30 16:05:44 -07:00
this.enableGrab();
2016-07-01 15:19:37 -07:00
Script.setTimeout(function() {
2016-07-08 13:37:59 -07:00
print('fully exited teleport mode')
2016-07-01 15:19:37 -07:00
inTeleportMode = false;
}, 100);
2016-06-30 16:05:44 -07:00
};
2016-07-01 11:12:20 -07:00
2016-07-08 13:37:59 -07:00
this.update = function() {
2016-07-07 12:12:22 -07:00
if (teleporter.teleportHand === 'left') {
teleporter.leftRay();
if ((leftPad.buttonValue === 0 || leftTrigger.buttonValue === 0) && inTeleportMode === true) {
print('TELEPORTING LEFT')
2016-07-07 12:12:22 -07:00
_this.teleport();
return;
}
} else {
teleporter.rightRay();
if ((rightPad.buttonValue === 0 || rightTrigger.buttonValue === 0) && inTeleportMode === true) {
print('TELEPORTING RIGHT')
2016-07-07 12:12:22 -07:00
_this.teleport();
return;
}
}
};
2016-06-30 16:05:44 -07:00
this.rightRay = function() {
2016-06-30 16:05:44 -07:00
var rightPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.RightHand).translation), MyAvatar.position);
var rightControllerRotation = Controller.getPoseValue(Controller.Standard.RightHand).rotation;
2016-06-30 16:05:44 -07:00
var rightRotation = Quat.multiply(MyAvatar.orientation, rightControllerRotation)
2016-06-30 16:05:44 -07:00
var rightFinal = Quat.multiply(rightRotation, Quat.angleAxis(90, {
x: 1,
y: 0,
z: 0
}));
var rightPickRay = {
origin: rightPosition,
direction: Quat.getUp(rightRotation),
};
2016-06-30 16:05:44 -07:00
this.rightPickRay = rightPickRay;
var location = Vec3.sum(rightPickRay.origin, Vec3.multiply(rightPickRay.direction, 500));
2016-07-06 15:16:31 -07:00
2016-06-30 16:05:44 -07:00
var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity]);
if (rightIntersection.intersects) {
2016-07-06 15:19:10 -07:00
this.rightLineOn(rightPickRay.origin, rightIntersection.intersection, {
red: 7,
green: 36,
blue: 44
});
if (this.targetOverlay !== null) {
this.updateTargetOverlay(rightIntersection);
} else {
this.createTargetOverlay();
}
2016-07-06 12:31:03 -07:00
2016-07-06 15:16:31 -07:00
} else {
2016-07-06 15:19:10 -07:00
this.rightLineOn(rightPickRay.origin, location, {
red: 7,
green: 36,
blue: 44
});
2016-07-06 15:16:31 -07:00
this.deleteTargetOverlay();
2016-07-01 17:26:52 -07:00
}
}
2016-06-30 16:05:44 -07:00
this.leftRay = function() {
var leftPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.LeftHand).translation), MyAvatar.position);
var leftRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(Controller.Standard.LeftHand).rotation)
2016-06-30 16:05:44 -07:00
var leftFinal = Quat.multiply(leftRotation, Quat.angleAxis(90, {
x: 1,
y: 0,
z: 0
}));
var leftPickRay = {
origin: leftPosition,
direction: Quat.getUp(leftRotation),
};
2016-06-30 16:05:44 -07:00
this.leftPickRay = leftPickRay;
2016-07-06 15:16:31 -07:00
var location = Vec3.sum(MyAvatar.position, Vec3.multiply(leftPickRay.direction, 500));
var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity]);
2016-06-30 16:05:44 -07:00
if (leftIntersection.intersects) {
2016-07-06 15:16:31 -07:00
2016-07-06 15:19:10 -07:00
this.leftLineOn(leftPickRay.origin, leftIntersection.intersection, {
red: 7,
green: 36,
blue: 44
});
if (this.targetOverlay !== null) {
this.updateTargetOverlay(leftIntersection);
} else {
this.createTargetOverlay();
}
2016-07-06 15:16:31 -07:00
} else {
2016-07-06 15:19:10 -07:00
this.leftLineOn(leftPickRay.origin, location, {
red: 7,
green: 36,
blue: 44
});
2016-07-06 15:16:31 -07:00
this.deleteTargetOverlay();
}
};
this.rightLineOn = function(closePoint, farPoint, color) {
// draw a line
if (this.rightOverlayLine === null) {
var lineProperties = {
start: closePoint,
end: farPoint,
color: color,
ignoreRayIntersection: true, // always ignore this
visible: true,
alpha: 1,
solid: true,
drawInFront: true,
2016-07-06 15:16:31 -07:00
glow: 1.0
};
this.rightOverlayLine = Overlays.addOverlay("line3d", lineProperties);
2016-07-06 12:31:03 -07:00
} else {
2016-07-06 15:16:31 -07:00
var success = Overlays.editOverlay(this.rightOverlayLine, {
lineWidth: 50,
start: closePoint,
end: farPoint,
color: color,
visible: true,
ignoreRayIntersection: true, // always ignore this
2016-07-08 13:13:32 -07:00
alpha: 1,
glow: 1.0
2016-07-06 15:16:31 -07:00
});
}
};
2016-07-06 12:31:03 -07:00
2016-07-06 15:16:31 -07:00
this.leftLineOn = function(closePoint, farPoint, color) {
if (this.leftOverlayLine === null) {
var lineProperties = {
ignoreRayIntersection: true, // always ignore this
start: closePoint,
end: farPoint,
color: color,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
drawInFront: true
2016-07-06 15:16:31 -07:00
};
2016-06-30 16:05:44 -07:00
2016-07-06 15:16:31 -07:00
this.leftOverlayLine = Overlays.addOverlay("line3d", lineProperties);
2016-06-30 16:05:44 -07:00
2016-07-06 15:16:31 -07:00
} else {
var success = Overlays.editOverlay(this.leftOverlayLine, {
start: closePoint,
end: farPoint,
color: color,
visible: true,
alpha: 1,
solid: true,
glow: 1.0
});
}
};
this.rightOverlayOff = function() {
if (this.rightOverlayLine !== null) {
Overlays.deleteOverlay(this.rightOverlayLine);
this.rightOverlayLine = null;
2016-06-30 16:05:44 -07:00
}
};
2016-07-06 15:16:31 -07:00
this.leftOverlayOff = function() {
if (this.leftOverlayLine !== null) {
Overlays.deleteOverlay(this.leftOverlayLine);
this.leftOverlayLine = null;
}
};
2016-07-01 15:19:37 -07:00
this.updateTargetOverlay = function(intersection) {
2016-07-06 17:52:18 -07:00
_this.intersection = intersection;
2016-07-06 13:20:42 -07:00
var rotation = Quat.lookAt(intersection.intersection, MyAvatar.position, Vec3.UP)
2016-07-06 13:20:42 -07:00
var euler = Quat.safeEulerAngles(rotation)
2016-06-30 16:05:44 -07:00
var position = {
x: intersection.intersection.x,
2016-07-06 13:20:42 -07:00
y: intersection.intersection.y + TARGET_MODEL_DIMENSIONS.y / 2,
2016-06-30 16:05:44 -07:00
z: intersection.intersection.z
}
2016-07-01 15:19:37 -07:00
Overlays.editOverlay(this.targetOverlay, {
2016-07-01 17:26:52 -07:00
position: position,
rotation: Quat.fromPitchYawRollDegrees(0, euler.y, 0),
2016-06-30 16:05:44 -07:00
});
2016-07-01 15:19:53 -07:00
2016-06-30 16:05:44 -07:00
};
this.disableGrab = function() {
Messages.sendLocalMessage('Hifi-Hand-Disabler', this.teleportHand);
2016-06-30 16:05:44 -07:00
};
this.enableGrab = function() {
Messages.sendLocalMessage('Hifi-Hand-Disabler', 'none');
};
this.triggerHaptics = function() {
var hand = this.teleportHand === 'left' ? 0 : 1;
var haptic = Controller.triggerShortHapticPulse(0.2, hand);
};
2016-06-30 16:05:44 -07:00
this.teleport = function(value) {
2016-07-08 13:37:59 -07:00
print('teleporting : ' + value)
2016-07-07 14:37:51 -07:00
if (this.intersection !== null) {
if (USE_FADE_MODE === true) {
this.createFadeSphere();
}
var offset = getAvatarFootOffset();
2016-07-07 14:37:51 -07:00
this.intersection.intersection.y += offset;
2016-07-06 17:52:18 -07:00
// MyAvatar.position = _this.intersection.intersection;
2016-07-06 18:13:42 -07:00
this.exitTeleportMode();
2016-07-06 17:52:18 -07:00
this.smoothArrival();
2016-07-06 18:13:42 -07:00
2016-07-06 17:52:18 -07:00
}
};
this.getArrivalPoints = function(startPoint, endPoint) {
var arrivalPoints = [];
var i;
var lastPoint;
for (i = 0; i < NUMBER_OF_STEPS; i++) {
if (i === 0) {
lastPoint = startPoint;
}
var newPoint = _this.findMidpoint(lastPoint, endPoint);
lastPoint = newPoint;
arrivalPoints.push(newPoint);
}
2016-07-06 17:52:18 -07:00
arrivalPoints.push(endPoint)
return arrivalPoints
2016-06-30 16:05:44 -07:00
};
2016-07-06 17:52:18 -07:00
this.smoothArrival = function() {
_this.arrivalPoints = _this.getArrivalPoints(MyAvatar.position, _this.intersection.intersection);
print('ARRIVAL POINTS: ' + JSON.stringify(_this.arrivalPoints));
print('end point: ' + JSON.stringify(_this.intersection.intersection))
_this.smoothArrivalInterval = Script.setInterval(function() {
2016-07-06 18:13:42 -07:00
print(_this.arrivalPoints.length + " arrival points remaining")
2016-07-06 17:52:18 -07:00
if (_this.arrivalPoints.length === 0) {
Script.clearInterval(_this.smoothArrivalInterval);
return;
}
var landingPoint = _this.arrivalPoints.shift();
print('landing at: ' + JSON.stringify(landingPoint))
2016-07-06 18:13:42 -07:00
MyAvatar.position = landingPoint;
2016-07-07 14:37:51 -07:00
if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) {
print('clear target overlay')
_this.deleteTargetOverlay();
_this.triggerHaptics();
}
2016-07-06 17:52:18 -07:00
}, SMOOTH_ARRIVAL_SPACING)
}
2016-06-29 18:28:39 -07:00
}
2016-06-29 15:59:51 -07:00
2016-06-30 16:05:44 -07:00
//related to repositioning the avatar after you teleport
2016-06-29 18:28:39 -07:00
function getAvatarFootOffset() {
var data = getJointData();
var upperLeg, lowerLeg, foot, toe, toeTop;
data.forEach(function(d) {
var jointName = d.joint;
if (jointName === "RightUpLeg") {
upperLeg = d.translation.y;
}
if (jointName === "RightLeg") {
lowerLeg = d.translation.y;
}
if (jointName === "RightFoot") {
foot = d.translation.y;
}
if (jointName === "RightToeBase") {
toe = d.translation.y;
}
if (jointName === "RightToe_End") {
toeTop = d.translation.y
}
})
var myPosition = MyAvatar.position;
var offset = upperLeg + lowerLeg + foot + toe + toeTop;
offset = offset / 100;
return offset
};
function getJointData() {
var allJointData = [];
var jointNames = MyAvatar.jointNames;
jointNames.forEach(function(joint, index) {
var translation = MyAvatar.getJointTranslation(index);
var rotation = MyAvatar.getJointRotation(index)
allJointData.push({
joint: joint,
index: index,
translation: translation,
rotation: rotation
});
});
return allJointData;
};
2016-07-01 11:12:20 -07:00
2016-06-30 16:05:44 -07:00
var leftPad = new ThumbPad('left');
var rightPad = new ThumbPad('right');
var leftTrigger = new Trigger('left');
var rightTrigger = new Trigger('right');
//create a controller mapping and make sure to disable it when the script is stopped
2016-07-01 11:12:20 -07:00
var mappingName, teleportMapping;
2016-07-07 11:42:41 -07:00
var TELEPORT_DELAY = 100;
2016-07-07 12:12:22 -07:00
2016-07-08 13:37:59 -07:00
function registerMappings() {
2016-07-07 12:12:22 -07:00
mappingName = 'Hifi-Teleporter-Dev-' + Math.random();
teleportMapping = Controller.newMapping(mappingName);
teleportMapping.from(Controller.Standard.RT).peek().to(rightTrigger.buttonPress);
teleportMapping.from(Controller.Standard.LT).peek().to(leftTrigger.buttonPress);
teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightPad.buttonPress);
teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftPad.buttonPress);
teleportMapping.from(leftPad.down).when(leftTrigger.down).to(function(value) {
2016-07-08 13:37:59 -07:00
print('tel 1')
2016-07-07 12:12:22 -07:00
teleporter.enterTeleportMode('left')
2016-07-08 13:37:59 -07:00
return;
2016-07-07 12:12:22 -07:00
});
teleportMapping.from(rightPad.down).when(rightTrigger.down).to(function(value) {
2016-07-08 13:37:59 -07:00
print('tel 2')
2016-07-07 12:12:22 -07:00
teleporter.enterTeleportMode('right')
2016-07-08 13:37:59 -07:00
return;
2016-07-07 12:12:22 -07:00
});
teleportMapping.from(leftTrigger.down).when(leftPad.down).to(function(value) {
2016-07-08 13:37:59 -07:00
print('tel 3')
teleporter.enterTeleportMode('left')
2016-07-08 13:37:59 -07:00
return;
});
teleportMapping.from(rightTrigger.down).when(rightPad.down).to(function(value) {
2016-07-08 13:37:59 -07:00
print('tel 4')
teleporter.enterTeleportMode('right')
2016-07-08 13:37:59 -07:00
return;
});
2016-07-01 11:12:20 -07:00
}
2016-06-30 16:05:44 -07:00
2016-07-08 13:37:59 -07:00
registerMappings();
2016-07-07 12:39:11 -07:00
2016-06-30 16:05:44 -07:00
var teleporter = new Teleporter();
Controller.enableMapping(mappingName);
Script.scriptEnding.connect(cleanup);
function cleanup() {
teleportMapping.disable();
teleporter.disableMappings();
teleporter.deleteTargetOverlay();
2016-07-06 15:16:31 -07:00
teleporter.turnOffOverlayBeams();
2016-07-07 14:37:51 -07:00
teleporter.deleteFadeSphere();
2016-06-30 16:05:44 -07:00
if (teleporter.updateConnected !== null) {
2016-07-07 12:39:11 -07:00
if (USE_THUMB_AND_TRIGGER_MODE === true) {
Script.update.disconnect(teleporter.updateForThumbAndTrigger);
} else {
Script.update.disconnect(teleporter.update);
}
2016-06-30 16:05:44 -07:00
}
}