mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 10:42:35 +02:00
Created script for spherical gravity.
This commit is contained in:
parent
8b978beb31
commit
e900dae708
1 changed files with 55 additions and 0 deletions
55
unpublishedScripts/gravity.js
Normal file
55
unpublishedScripts/gravity.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// gravity.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Alan-Michael Moody on 7/24/17
|
||||
// Copyright 2016 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
|
||||
//
|
||||
|
||||
(function () {
|
||||
|
||||
var _entityID;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
_entityID = entityID;
|
||||
};
|
||||
|
||||
function update(deltatime) {
|
||||
var planet = Entities.getEntityProperties(_entityID);
|
||||
var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, planet.position));
|
||||
var localUp = Quat.getUp(MyAvatar.orientation);
|
||||
|
||||
MyAvatar.orientation = Quat.multiply(Quat.rotationBetween(localUp, direction), MyAvatar.orientation);
|
||||
}
|
||||
|
||||
function init() {
|
||||
Script.update.connect(update);
|
||||
}
|
||||
|
||||
function clean() {
|
||||
Script.update.disconnect(update);
|
||||
MyAvatar.orientation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
}
|
||||
|
||||
var _switch = true;
|
||||
|
||||
this.clickDownOnEntity = function(uuid, mouseEvent) {
|
||||
|
||||
if (_switch) {
|
||||
init();
|
||||
} else {
|
||||
clean();
|
||||
}
|
||||
_switch = !_switch;
|
||||
};
|
||||
|
||||
Script.scriptEnding.connect(clean);
|
||||
|
||||
});
|
Loading…
Reference in a new issue