Teleport on mouse touch


#1

From a very newbie scripter…
Following script reads userdata where there should be a path obtained by navigation -> copy path menu.
for instance: /-387.447,3.03851,204.482/0,0.977336,0,-0.211693

When user clicks the object with the script and userdata is quickly teleported to the destination.

Hope this can help some people willing to learn scripting in HiFi, with some minimal examples.

Server script:

(function () {
var path = null;
var properties = null;
this.clickDownOnEntity = function (entityID, mouseEvent) {
properties = Entities.getEntityProperties(entityID, [“position”, “userData”]);
if (!properties.userData) {
print(“Click Teleporter " + entityID + " missing user data.”);
return;
} try {
teleportData = JSON.parse(properties.userData);
print("Path " + teleportData.path);
url = location.hostname;
location = “hifi://” + url + teleportData.path;
} catch (e) { }
}
})

UserData:

{
“path”: “/path obtained with navigate copy path”,
“grabbableKey”: {
“grabbable”: false
}
}