Skip to content

Commit

Permalink
fix: Fixes horizontal velocity when on platform (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Flerackers <[email protected]>
  • Loading branch information
mflerackers and Marc Flerackers authored May 25, 2024
1 parent 29b3bd5 commit 8eacea8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4577,6 +4577,8 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
willFall = false;
}

let updateY = true;

if (curPlatform) {
if (
// TODO: this prevents from falling when on edge
Expand All @@ -4595,20 +4597,22 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
);
}
lastPlatformPos = curPlatform.pos;
return;
updateY = false;
}
}

const prevVelY = this.vel.y;
if (updateY) {
const prevVelY = this.vel.y;

this.vel.y += game.gravity * this.gravityScale * dt();
this.vel.y = Math.min(
this.vel.y,
opt.maxVelocity ?? MAX_VEL,
);
this.vel.y += game.gravity * this.gravityScale * dt();
this.vel.y = Math.min(
this.vel.y,
opt.maxVelocity ?? MAX_VEL,
);

if (prevVelY < 0 && this.vel.y >= 0) {
this.trigger("fall");
if (prevVelY < 0 && this.vel.y >= 0) {
this.trigger("fall");
}
}
}

Expand Down

0 comments on commit 8eacea8

Please sign in to comment.