content/hifi-content/rebecca/LedWorld/BallPit/rollerCoaster.js
2022-02-14 02:04:11 +01:00

43 lines
1.6 KiB
JavaScript

(function () {
var UPDATE_POSITION_INTERVAL_MS=1000/90;
var toggle = false;
var car = "{e22f934b-0a14-445e-9772-4285549cc12f}";
var interval;
Entities.editEntity(car,{visible:true});
var updateToggle = function(){
if (toggle){
toggle = false;
} else {
toggle = true;
}
};
this.enterEntity=function(entityID){
if (toggle){
Entities.editEntity("{5091a0d8-8cfe-40d6-bcf5-f9451b3e4174}",{animation:{running:0}});
Entities.editEntity(car,{visible:true});
Script.clearInterval(interval);
updateToggle();
} else {
Entities.editEntity(car,{visible:false});
Entities.editEntity("{5091a0d8-8cfe-40d6-bcf5-f9451b3e4174}",{animation:{running:1}});
interval = Script.setInterval(function() {
var nextPosition = Entities.getEntityProperties(car, 'position').position;
if (Vec3.distance(MyAvatar.position, nextPosition) < 5.0) {
MyAvatar.position = Entities.getEntityProperties(car,'position').position;
} else {
if (interval){
Entities.editEntity("{5091a0d8-8cfe-40d6-bcf5-f9451b3e4174}",{animation:{running:0}});
Script.clearInterval(interval);
updateToggle();
Entities.editEntity(car,{visible:true});
}
}
}, UPDATE_POSITION_INTERVAL_MS);
updateToggle();
}
};
});