content/hifi-content/wadewatts/Fluffy gravity script/spheregrav.js
2022-02-14 02:04:11 +01:00

30 lines
No EOL
762 B
JavaScript

(function() {
var _entityID = null;
var sphereGravTimer;
function sphereGrav() {
var pos = Entities.getEntityProperties(_entityID, ["position"])["position"];
var surfaceNormal = Vec3.subtract(MyAvatar.position,pos);
var rot = Quat.multiply(Quat.rotationBetween(Quat.getUp(MyAvatar.orientation),surfaceNormal),MyAvatar.orientation);
MyAvatar.orientation = rot;
return;
}
this.preload = function(entityID) {
_entityID = entityID;
};
this.enterEntity = function(entityID) {
sphereGravTimer = Script.setInterval(sphereGrav, 100);
};
this.leaveEntity = function(entityID) {
Script.clearInterval(sphereGravTimer);
MyAvatar.orientation = {w:1, x:0, y:0, z:0};
};
})