content/hifi-content/wadewatts/elevator for hanger 1.js
2022-02-14 02:04:11 +01:00

52 lines
No EOL
1.5 KiB
JavaScript

//
// elevator.js
//
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* globals Script Entities Vec3 */
(function() {
var pointA = {x: -1249.4025, y: -0.7704, z: -496.8633};
var pointB = {x: -1249.4025, y: 17.9683, z: -496.8633};
var pauseTime = 4; // seconds
var MOVE_TIME = 5;
var movingIntervalGlobal = (pauseTime + MOVE_TIME) * 1000;
var goingUp = false;
var _entityID;
this.preload = function(entityID) {
_entityID = entityID;
Script.setInterval(function() {
movePlatform(goingUp);
goingUp = !goingUp;
}, movingIntervalGlobal);
};
var movePlatform = function(isGoingUp) {
var from = isGoingUp ? pointA : pointB;
var to = isGoingUp ? pointB : pointA;
var moveTime = MOVE_TIME;
var moveDirection = Vec3.subtract(to , from);
var moveVelocity = Vec3.multiply(moveDirection, 1 / moveTime);
var movingSingleDirectionInterval = moveTime * 1000;
Entities.editEntity(_entityID, {
velocity: moveVelocity,
position: from,
damping: 0
});
Script.setTimeout(function() {
Entities.editEntity(_entityID, {
velocity: {x: 0, y: 0, z: 0},
position: to
});
}, movingSingleDirectionInterval);
};
});