Entity is not defined

I’m getting this error when i’m trying to make a script for a lift.

Lift.attributes.add('upTarget', {
    type: 'entity'
Lift.attributes.add('downTarget', {
    type: 'entity'

// initialize code called once per entity
Lift.prototype.initialize = function() {
Lift.prototype.initialize = function(otherEntity) {

// swap method called for script hot-reloading
// inherit your script state here
// Lift.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

It should be this.entity, not entity.

Also, there’s no function called translate on the rigidbody component. Instead, there is teleport.

In this case, you have a lift (elevator). This is probably best done as a kinematic body. You can move kinematic bodies around with the regular translate function on the entity itself (you only need teleport for dynamic and static bodies). So:

    this.entity.translate(x, y, z);

I changed those things about the script, but now it gives me this: lerp is not defined

Do I still need to use that or will it slowly move up?

There is no such function as lerp in JavaScript. PlayCanvas provides an implementation for pc.Vec3 though:


To lerp an entity from one point to another, you would have to accumulate a timer and use that as the third parameter to the lerp function.

1 Like