[SOLVED] Why is the object not deleted when it gets below -1

Hello. Why is the object not deleted when it gets below -1

var Testingmove = pc.createScript('testingmove');

Testingmove.attributes.add('speed',{ type: 'number'});
let boost = 0;
let speedLOL = this.speed + boost;

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

};

// update code called every frame
Testingmove.prototype.update = function(dt) {
    if(this.app.keyboard.isPressed(pc.KEY_W)){
        this.entity.rigidbody.applyForce(0,0,-this.speed);
    }
    if(this.app.keyboard.isPressed(pc.KEY_S)){
        this.entity.rigidbody.applyForce(0,0,this.speed);
    }
    if(this.app.keyboard.isPressed(pc.KEY_D)){
        this.entity.rigidbody.applyForce(this.speed,0,0);
    }
    if(this.app.keyboard.isPressed(pc.KEY_A)){
        this.entity.rigidbody.applyForce(-this.speed,0,0);
    }
    if(this.app.keyboard.isPressed(pc.KEY_Z) && this.app.keyboard.isPressed(pc.KEY_X) && this.app.keyboard.isPressed(pc.KEY_C)){
        alert('hello');
        ez = prompt('How are you?');
        if(ez == 'sup'){
            alert('Hack activated');
            this.entity.rigidbody.applyForce(0,1000,0);
        }
        
    }
};

Testingmove.prototype.position = function(dt){
    position = this.entity.getPosition();
    if(position.y <= -1){
        this.entity.destroy();
    }
};

Hi @Stishka! Where do you execute the function position?

1 Like

my English does not let me understand your question

On line 37 you create a function that you need to execute somewhere. For example you can add this.position(); after line 34.

1 Like

Thank you. I’ll try to figure it out myself. I don’t understand you. Goodbye

haha :slight_smile: hello. I understood the meaning of your questions after I solved this problem ;D. Thank you


Testingmove.attributes.add('speed',{ type: 'number'});
let boost = 0;
let speedLOL = this.speed + boost;

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

};

// update code called every frame
Testingmove.prototype.update = function(dt) {
    if(this.app.keyboard.isPressed(pc.KEY_W)){
        this.entity.rigidbody.applyForce(0,0,-this.speed);
    }
    if(this.app.keyboard.isPressed(pc.KEY_S)){
        this.entity.rigidbody.applyForce(0,0,this.speed);
    }
    if(this.app.keyboard.isPressed(pc.KEY_D)){
        this.entity.rigidbody.applyForce(this.speed,0,0);
    }
    if(this.app.keyboard.isPressed(pc.KEY_A)){
        this.entity.rigidbody.applyForce(-this.speed,0,0);
    }
    if(this.app.keyboard.isPressed(pc.KEY_V)){
        alert('Destroying');
        this.entity.destroy();
    }
    if(this.app.keyboard.isPressed(pc.KEY_Z) && this.app.keyboard.isPressed(pc.KEY_X) && this.app.keyboard.isPressed(pc.KEY_C)){
        alert('hello');
        ez = prompt('How are you?');
        if(ez == 'sup'){
            alert('Hack activated');
            this.entity.rigidbody.applyForce(0,1000,0);
        }
        
    }
    position = this.entity.getPosition();
    if(position.y <= 0){
        this.entity.destroy();
    }
};

Yes, that’s the same result indeed. Good job!

1 Like