Help on Moving Platforms

i want moving platforms here’s my script

var Platform = pc.createScript('platform');

Platform.prototype.initialize = function() {
    this.velocity = new pc.Vec3();
    this.step = 0;
};


Platform.prototype.activate = function() {
    this.active = true;
};

Platform.v3 = new pc.Vec3();
Platform.prototype.getVelocity = function(dt) {
    var currentPosition = this.entity.getPosition();    
    var velocity = Platform.v3;
    if (!this.lastPosition) {
        this.lastPosition = new pc.Vec3().copy(currentPosition);
    } else {
        velocity.copy(currentPosition).sub(this.lastPosition).scale(1/dt);
        this.lastPosition.copy(currentPosition);
    }
    return velocity;
};

Platform.prototype.postUpdate = function(dt) {
    if (!this.active) return;
    
    this.step += dt * 4;
    this.entity.translate(Math.cos(this.step) * 0.3, 0, 0);
    var velocity = this.getVelocity(dt);    
    this.app.fire('update-velocity', velocity);
};

it doesnt work, and it doesn’t give me errors so

Hi @Deadshot1m24! Where do you execute the activate function? This function set the boolean this.active to true, which is needed to run your postUpdate function.

wait what do i replace/change?

You have three options. Execute the activate function somewhere (for example in the initialize function) or you can set the boolean this.active to true by default or you can disable the first line of the postUpdate function.