mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:17:58 +02:00
teleport.js drags avatar along
This commit is contained in:
parent
954d690b8a
commit
0d300c3a47
1 changed files with 45 additions and 29 deletions
|
@ -13,7 +13,10 @@
|
||||||
var inTeleportMode = false;
|
var inTeleportMode = false;
|
||||||
|
|
||||||
var SMOOTH_ARRIVAL_SPACING = 33;
|
var SMOOTH_ARRIVAL_SPACING = 33;
|
||||||
var NUMBER_OF_STEPS = 6;
|
var NUMBER_OF_STEPS_FOR_TELEPORT = 6;
|
||||||
|
|
||||||
|
var AVATAR_DRAG_SPACING = 33;
|
||||||
|
var NUMBER_OF_STEPS_FOR_AVATAR_DRAG = 12;
|
||||||
|
|
||||||
var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport-destination.fbx");
|
var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport-destination.fbx");
|
||||||
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../assets/models/teleport-cancel.fbx");
|
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../assets/models/teleport-cancel.fbx");
|
||||||
|
@ -88,6 +91,8 @@ function Teleporter() {
|
||||||
this.cancelOverlay = null;
|
this.cancelOverlay = null;
|
||||||
this.updateConnected = null;
|
this.updateConnected = null;
|
||||||
this.smoothArrivalInterval = null;
|
this.smoothArrivalInterval = null;
|
||||||
|
this.dragAvatarInterval = null;
|
||||||
|
this.oldAvatarCollisionsEnabled = MyAvatar.avatarCollisionsEnabled;
|
||||||
this.teleportHand = null;
|
this.teleportHand = null;
|
||||||
this.distance = 0.0;
|
this.distance = 0.0;
|
||||||
this.teleportMode = "HMDAndAvatarTogether";
|
this.teleportMode = "HMDAndAvatarTogether";
|
||||||
|
@ -132,6 +137,10 @@ function Teleporter() {
|
||||||
if (this.smoothArrivalInterval !== null) {
|
if (this.smoothArrivalInterval !== null) {
|
||||||
Script.clearInterval(this.smoothArrivalInterval);
|
Script.clearInterval(this.smoothArrivalInterval);
|
||||||
}
|
}
|
||||||
|
if (this.dragAvatarInterval !== null) {
|
||||||
|
Script.clearInterval(this.dragAvatarInterval);
|
||||||
|
MyAvatar.avatarCollisionsEnabled = _this.oldAvatarCollisionsEnabled;
|
||||||
|
}
|
||||||
if (activationTimeout !== null) {
|
if (activationTimeout !== null) {
|
||||||
Script.clearInterval(activationTimeout);
|
Script.clearInterval(activationTimeout);
|
||||||
}
|
}
|
||||||
|
@ -524,32 +533,27 @@ function Teleporter() {
|
||||||
this.teleportMode = "AvatarOnly";
|
this.teleportMode = "AvatarOnly";
|
||||||
}
|
}
|
||||||
this.smoothArrival();
|
this.smoothArrival();
|
||||||
|
if (this.teleportMode === "HMDFirstAvatarWillFollow") {
|
||||||
|
this.dragAvatarCollisionlessly();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.findMidpoint = function(start, end) {
|
this.getWayPoints = function(startPoint, endPoint, numberOfSteps) {
|
||||||
var xy = Vec3.sum(start, end);
|
var travel = Vec3.subtract(endPoint - startPoint);
|
||||||
var midpoint = Vec3.multiply(0.5, xy);
|
var distance = Vec3.length(travel);
|
||||||
return midpoint
|
if (distance > 1.0) {
|
||||||
};
|
var base = Math.exp(log(distance + 1.0) / numberOfSteps);
|
||||||
|
var wayPoints = [];
|
||||||
this.getArrivalPoints = function(startPoint, endPoint) {
|
|
||||||
var arrivalPoints = [];
|
|
||||||
var i;
|
var i;
|
||||||
var lastPoint;
|
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_STEPS; i++) {
|
for (i = 0; i < numberOfSteps - 1; i++) {
|
||||||
if (i === 0) {
|
var backFraction = (1.0 - Math.exp((numberOfSteps - 1 - i) * Math.log(base))) / distance;
|
||||||
lastPoint = startPoint;
|
wayPoints.push(Vec3.sum(endPoint, Vec3.multiply(backFraction, travel));
|
||||||
}
|
}
|
||||||
var newPoint = _this.findMidpoint(lastPoint, endPoint);
|
|
||||||
lastPoint = newPoint;
|
|
||||||
arrivalPoints.push(newPoint);
|
|
||||||
}
|
}
|
||||||
|
wayPoints.push(endPoint);
|
||||||
arrivalPoints.push(endPoint);
|
return wayPoints;
|
||||||
|
|
||||||
return arrivalPoints;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.teleportTo = function(landingPoint) {
|
this.teleportTo = function(landingPoint) {
|
||||||
|
@ -569,25 +573,37 @@ function Teleporter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.smoothArrival = function() {
|
this.smoothArrival = function() {
|
||||||
|
_this.teleportPoints = _this.getWayPoints(MyAvatar.position, _this.intersection.intersection, NUMBER_OF_STEPS_FOR_TELEPORT);
|
||||||
_this.arrivalPoints = _this.getArrivalPoints(MyAvatar.position, _this.intersection.intersection);
|
|
||||||
_this.smoothArrivalInterval = Script.setInterval(function() {
|
_this.smoothArrivalInterval = Script.setInterval(function() {
|
||||||
if (_this.arrivalPoints.length === 0) {
|
if (_this.teleportPoints.length === 0) {
|
||||||
Script.clearInterval(_this.smoothArrivalInterval);
|
Script.clearInterval(_this.smoothArrivalInterval);
|
||||||
HMD.centerUI();
|
HMD.centerUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var landingPoint = _this.arrivalPoints.shift();
|
var landingPoint = _this.teleportPoints.shift();
|
||||||
_this.teleportTo(landingPoint);
|
_this.teleportTo(landingPoint);
|
||||||
|
|
||||||
if (_this.arrivalPoints.length === 1 || _this.arrivalPoints.length === 0) {
|
if (_this.teleportPoints.length === 1 || _this.teleportPoints.length === 0) {
|
||||||
_this.deleteTargetOverlay();
|
_this.deleteTargetOverlay();
|
||||||
_this.deleteCancelOverlay();
|
_this.deleteCancelOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, SMOOTH_ARRIVAL_SPACING);
|
}, SMOOTH_ARRIVAL_SPACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dragAvatarCollisionlessly = function() {
|
||||||
|
_this.oldAvatarCollisionsEnabled = MyAvatar.avatarCollisionsEnabled;
|
||||||
|
MyAvatar.avatarCollisionsEnabled = false;
|
||||||
|
_this.dragPoints = _this.getWayPoints(MyAvatar.position, _this.intersection.intersection, NUMBER_OF_STEPS_FOR_AVATAR_DRAG);
|
||||||
|
_this.dragAvatarInterval = Script.setInterval(function() {
|
||||||
|
if (_this.dragPoints.length === 0) {
|
||||||
|
Script.clearInterval(_this.dragAvatarInterval);
|
||||||
|
MyAvatar.avatarCollisionsEnabled = _this.oldAvatarCollisionsEnabled;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var landingPoint = _this.dragPoints.shift();
|
||||||
|
MyAvatar.position = landingPoint;
|
||||||
|
}, AVATAR_DRAG_SPACING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue