I tried this code in this isn’t working in the game?
var Jump = pc.createScript('jump');
var onGround = false;
var jumpForce = 4; // Change to whatever you want
Jump.prototype.initialize = function() {
// Define Events
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Jump.prototype.update = function(dt) {
// Jump
if (this.app.keyboard.wasPressed(pc.KEY_SPACE) && onGround === true) {
this.entity.rigidbody.applyImpulse(4, jumpForce, 4); // Apply Impulse
onGround = false; // Set onGround variable to false
}
};
Jump.prototype.onCollisionStart = function(result) {
// Ground Check
if (result.other.tags.has('ground')) {
onGround = true;
}
};