Skip to content

Commit

Permalink
dont apply gravity to static objects (if mass is 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Nov 25, 2024
1 parent 9a97f92 commit 7ab6b1a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/engineObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,18 @@ class EngineObject

// apply physics
const oldPos = this.pos.copy();
this.pos.x += this.velocity.x *= this.damping;
this.pos.y += this.velocity.y = this.damping * this.velocity.y
+ gravity * this.gravityScale;
this.velocity.x *= this.damping;
this.velocity.y *= this.damping;
if (this.mass) // dont apply gravity to static objects
this.velocity.y += gravity * this.gravityScale;
this.pos.x += this.velocity.x;
this.pos.y += this.velocity.y;
this.angle += this.angleVelocity *= this.angleDamping;

// physics sanity checks
ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
ASSERT(this.damping >= 0 && this.damping <= 1);
if (!enablePhysicsSolver || !this.mass) // dont do collision for fixed objects
if (!enablePhysicsSolver || !this.mass) // dont do collision for static objects
return;

const wasMovingDown = this.velocity.y < 0;
Expand Down

0 comments on commit 7ab6b1a

Please sign in to comment.