[SOLVED] 2d character won't jump

Hi, my 2d character won’t jump and I really don’t know why :')) the animation only plays when i press the button but there’s no “jumping happening” pls help :sob: this is the code:

var Sable = pc.createScript('sable');
var movementSpeed = 30;
var jumpForce = 5000;

// initialize code called once per entity
Sable.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};

// update code called every frame
Sable.prototype.update = function(dt) {
    
// Move right
    if (this.app.keyboard.isPressed(pc.KEY_D) || this.app.keyboard.isPressed(pc.KEY_RIGHT)) {
        this.entity.sprite.play("Sable_runR");
        this.entity.rigidbody.applyForce(movementSpeed, 0, 0);
    }

// Move left
    if (this.app.keyboard.isPressed(pc.KEY_A) || this.app.keyboard.isPressed(pc.KEY_LEFT)) {
        this.entity.sprite.play("Sable_runL");
        this.entity.rigidbody.applyForce(-movementSpeed, 0, 0);
    }

// Jump
    if (this.app.keyboard.wasPressed(pc.KEY_W)) {
        this.entity.rigidbody.applyImpulse(0, jumpForce, 0); // Apply upward forc
        this.entity.sprite.play("Sable_jumpR");
    }

 // Play idle animation when no keys are pressed and not jumping
    if (!this.app.keyboard.isPressed(pc.KEY_W) &&
        !this.app.keyboard.isPressed(pc.KEY_D) &&
        !this.app.keyboard.isPressed(pc.KEY_A)) {
        this.entity.sprite.play("Sable_idle");
    }
};

Is there a dynamic rigid body on your character?

yes there is :((

Hm. Can you please send a link for your editor?

I am not 100% certain what is happening, it should work. Try decreasing your restitution (idk what it does) If that doesn’t work I would check this page for anything I missed, maybe you could try Torque? Forces and Impulses | PlayCanvas Developer Site

I guess Linear Damping of the rigidbody should be set lower than 1, otherwise the force is completely dampened.

1 Like

thank you so much, this worked ;-;