[SOLVED] Why Wont My Player Move?

Hello all,
I am making a game with a wind power-up that when you are holding it will launch you in the air.
Here is my code:

var Powerup = pc.createScript('powerup');
let holding = false;
Powerup.attributes.add('wpMODEL', {
    type: "entity",
})
Powerup.attributes.add('wp', {
    type: "entity",
})
// initialize code called once per entity
Powerup.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    this.entity.collision.on('collisionend', this.onCollisionEnd, this);
};

// update code called every frame
Powerup.prototype.update = function (dt) {
    if (holding === 'wind') {
        this.wpMODEL.enabled = true;
        this.wp.enabled = false;
        if (this.app.keyboard.isPressed(pc.KEY_Q)) {
            this.entity.translate(0, 50, 0);
            this.wpMODEL.enabled = false;
            holding = false;
        }
    };
};

Powerup.prototype.onCollisionStart = function (result) {
    if (result.other.tags.has('wind')) {
        if (holding === false) {
            holding = 'wind';
        };
    };
};

No matter what I use in line 21, translate or impulse, it won’t make the character move. Everything else after that works. Can someone help me?

Is the entity not moving at all or just a little bit?

Please note, a function should be closed with }; but a statement should be closed with only }.

I’m also curious why you use the variable holding both as a boolean and string. I suggest to use it as a boolean with true and false or as a string with for example 'none' and 'wind'.

The entity is not moving at all.

Good to know.
I will try using it as a boolean.

I did some research on using booleans in js, here is my script:

var Powerup = pc.createScript('powerup');

Powerup.attributes.add('wpMODEL', {
    type: "entity",
})
Powerup.attributes.add('wp', {
    type: "entity",
})
let good = Boolean();
// initialize code called once per entity
Powerup.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    this.entity.collision.on('collisionend', this.onCollisionEnd, this);
};

// update code called every frame
Powerup.prototype.update = function (dt) {
    if (Boolean(good)=== true) {
        this.wpMODEL.enabled = true;
        this.wp.enabled = false;
        if (this.app.keyboard.isPressed(pc.KEY_Q)) {
            this.entity.translate(0, 0, 500);
            this.wpMODEL.enabled = false;
            holding = false;
            good = Boolean(false);
        }
    }
};
Powerup.prototype.onCollisionStart = function (result) {
    if (result.other.tags.has('wind')) {
        if (Boolean(good)=== false) {
            good = Boolean(true);
            pu = 'wind';
        }
    }
}; 

It only works if I take out line 25, but if I take out line 25, you can infinitely use the translate local.

Create a boolean:

let good = false;

Change a boolean:

good = true;

Use a boolean:

if (good === true) {
    // do something
}

Create a string:

let state = 'wrong';

Change a string:

state = 'good';

Use a string:

if (state === 'good') {
    // do something
}

Thanks for your help! It seems to work now!

1 Like

there is probably a bug in the program.

What is the bug @5rfutfuhiygyuo?

instead of if (state === ‘good’) try: if (state === ‘correct’) { if that does not work than your desktop is busted.

It depends on the string the user want to use.

1 Like

oh, yeah. i forgot about that.