From 7ab6b1a0c9553ef47a3fe63fa9124f42f9466e8b Mon Sep 17 00:00:00 2001 From: Frank Force Date: Mon, 25 Nov 2024 13:53:26 -0600 Subject: [PATCH] dont apply gravity to static objects (if mass is 0) --- src/engineObject.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engineObject.js b/src/engineObject.js index 4637d521..e7438738 100644 --- a/src/engineObject.js +++ b/src/engineObject.js @@ -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;