Elevator script


I want to share a simple script that creates an elevator.

  1. Create an invisible, collisionless cube, in the position, where you want the elevator.
  2. Create this script:
(function () {
this.enterEntity = function (entityID) {
var platform5;
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
  x: 0,
  y: -1,
  z: 0
}), Vec3.multiply(0.5, Quat.getForward(Camera.getOrientation())));
function init() {
    platform5 = Entities.addEntity({
        name: "platform5",
		type: "Shape",
        shape: "Cylinder",
        position: center,
        dimensions: { x: 3.3186, y: 0.2, z: 3.3186 },
        color: { red: 0, green: 0, blue: 0 },
        gravity: { x: 0, y: 0, z: 0 },
        visible: true,
        locked: false,
        lifetime: 50,
        velocity: { x: 0, y: 1, z: 0 },
        damping: 0,
        isDynamic: false,
		userData: JSON.stringify({
            grabbableKey: {
                grabbable: false
    if (platform5) {
        if (MyAvatar.getParentID() != platform5) {

function update(dt) {


function shutdown() {
    if (platform5) {

Script.setTimeout(init, 80);



3.Save this script as elevator.js
4.Hot your script on the atp server or somwhere on the net.
5.Put your hosted elevator.js script URL in the Script URL of the previously created box.
6.You can adjust the speed and the timer for the elevator, to rise at your desired location.
(by adjusting this variables: velocity, Script.setTimeout).

If you set the velocity different than zero on x and/or z you can have an elevator that move diagonally.

If you will have positive values for y velocity, the elevator will rise and if you will have negative values, it will
descend. You can create an elevator that rise up and another that will descend.


@GeorgeDeac this is fantastic script to learn scripting. It’s really working even in desktop mode (!).

Just a couple of questions from a newbie:

It is a bit unclear to me how this script is triggered… Should the avatar enter into the collisionless cube and when entering there it starts? Since it is collisionless, and it appears that the wizardry is triggered setting parent for my avatar to the “platform5” entity, when exactly the init() event will be triggered?
Does it work even in the desktop version or is it working only in the VR environment?


When an avatar enter inside the collision box, this.EnterEntity trigger is activated and the function init is called. It runs until the Script.setTimeout expires.


Thank you so much for this script. Now I can finally get the funicular on Franny to move.


@GeorgeDeac Another scripter newbie question :slight_smile:

you have in your code

var platform5;

and apparently you are checking this many times in your script.

Q: When does platform5 be set? There is no esplicit setting of it to a specific value.

Is it magically linked to the entity named platform5? Which is the difference between the platform var and platform5?

BTW: why the 5 in the name?


(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


Hi Claudio,
I have used this script in my domain for multiple elevators, from 1 to 6, This script is from elevator no.5 :slight_smile: . The platform is rezzed, when the avatar enter inside the collisionless box. The platform5 is positioned at your avatar position - 1 m on y axis, beeing dynamic with velocity specified on one or multiple axis, will move and transport the avatar with it.


My question was syntax specific. I have seen that this script is working, but I am failing to understand why it is working, since you are writing

platform = Entities.addEntity()

while I was expecting to find platform5 = Entities.addEntity().

I was expecting that at beginning

var platform;

instead of var platform5;
in short all platform5 in the source should be instead platform (s/platform5/platform/gp). If this is correct than me as a programmer can understand the source.

Maybe it is working anyway even if this was written wrongly. If such the script you published is wrong, otherwise something really weird and magical is happening here, and this is why I asked you :slight_smile:


I’ve corrected the code with platform5 instead of platform. The code worked without error in the previous state, so I didn’t noticed this. It seems that as you said, the entity name was “magically” associated to the variable. :slight_smile:


Thanks, now my mental sanity as newbie would-be HiFi scripter is restored :sunny: