Skip to content

Instantly share code, notes, and snippets.

@humbletim
Created March 24, 2017 00:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save humbletim/3432153e7a2dbfbf71d95ce85cb0151b to your computer and use it in GitHub Desktop.
(function(){
var teleport;
var portalDestination;
var animationURL;
var position;
function playSound(entityID) {
print("playing teleport sound");
if (teleport.downloaded) {
if(!position) {
getProps(entityID);
}
Audio.playSound(teleport, { position: position, volume: 0.40, localOnly: true });
}
};
function getProps(entityID) {
var properties = Entities.getEntityProperties(entityID);
if (properties) {
animationURL = properties.modelURL;
position = properties.position;
try { portalDestination=JSON.parse(properties.userData).portalDestination; } catch(e) {
portalDestination = properties.userData;
}
}
};
this.preload = function(entityID) {
print("loading teleport script");
teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw");
getProps(entityID);
};
this.enterEntity = function(entityID) {
// get latest props in case we changed the destination
getProps(entityID);
print("enterEntity() .... The portal destination is " + portalDestination);
if (portalDestination.length > 0) {
print("Teleporting to hifi://" + portalDestination);
Window.location = "hifi://" + portalDestination;
}
};
this.leaveEntity = function(entityID) {
print("leaveEntity() called ....");
if (!animationURL) {
getProps(entityID);
}
Entities.editEntity(entityID, {
animation: { url: animationURL, currentFrame: 1, running: false }
});
playSound(entityID);
};
this.hoverEnterEntity = function(entityID) {
print("hoverEnterEntity() called ....");
if (!animationURL) {
getProps(entityID);
}
Entities.editEntity(entityID, {
animation: { url: animationURL, fps: 24, firstFrame: 1, lastFrame: 25, currentFrame: 1, running: true, hold: true }
});
};
this.unload = function() {
print("unloading teleport script");
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment