forked from overte-org/overte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgravity.js
56 lines (43 loc) · 1.27 KB
/
gravity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// gravity.js
//
// Created by Alan-Michael Moody on 7/24/17
// 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
//
(function () {
var _entityID;
this.preload = function (entityID) {
_entityID = entityID;
};
function update(deltatime) {
var planet = Entities.getEntityProperties(_entityID);
//normalization happens in rotationBetween.
var direction = Vec3.subtract(MyAvatar.position, planet.position);
var localUp = Quat.getUp(MyAvatar.orientation);
MyAvatar.orientation = Quat.normalize(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);
});