(function() { var playing = false; var howLong = 1000*10; Messages.subscribe("com.realitybloc.observatory"); var buttonPressed = function() { Messages.sendMessage("com.realitybloc.observatory", "pressed"); //onMessageReceived("com.realitybloc.observatory", "playing"); } function onMessageReceived(chan, msg) { if (chan!="com.realitybloc.observatory") return; if (msg!="playing") return; if (playing) return; playing = true; // check if in range var observatoryEntityID = Entities.findEntitiesByName( "Observatory", MyAvatar.position, 1000000 )[0]; if (!observatoryEntityID) return; var inRange = false; var observatoryEntity = Entities.getEntityProperties(observatoryEntityID, ["position"]); inRange = (Vec3.distance(MyAvatar.position, observatoryEntity.position)<10); // inrange interval var inRangeInterval = Script.setInterval(function() { var observatoryEntity = Entities.getEntityProperties(observatoryEntityID, ["position"]); inRange = (Vec3.distance(MyAvatar.position, observatoryEntity.position)<10); }, 500); // rotate the player var dateNow = Date.now() var outOfRangeReset = true; var interval = Script.setInterval(function() { if (inRange && !HMD.active) { outOfRangeReset = false; var time = (Date.now()-dateNow); MyAvatar.orientation = Quat.multiply( Quat.cancelOutRollAndPitch(MyAvatar.orientation), Quat.fromPitchYawRollDegrees( //Math.sin(time*0.02)*0.5, 0, 0, Math.cos(time*0.01)*1 ) ); } else { if (outOfRangeReset) return; if (!HMD.active) MyAvatar.orientation = Quat.cancelOutRollAndPitch(MyAvatar.orientation); outOfRangeReset = true; } }, 1000/90); // clean up Script.setTimeout(function() { if (inRange && !HMD.active) MyAvatar.orientation = Quat.cancelOutRollAndPitch(MyAvatar.orientation); Script.clearInterval(inRangeInterval); Script.clearInterval(interval); playing = false; }, howLong); } Messages.messageReceived.connect(onMessageReceived); Script.scriptEnding.connect(function () { Messages.messageReceived.disconnect(onMessageReceived); }); this.startNearTrigger = buttonPressed; this.startFarTrigger = buttonPressed; this.clickDownOnEntity = function(entityID, mouseEvent) { if (mouseEvent.isLeftButton) buttonPressed(); } })