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 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");
}
};