From dd72203862df2695d9c2b91d1ad3ac55345bca1c Mon Sep 17 00:00:00 2001 From: Karan Mhetar Date: Sat, 16 May 2026 14:56:58 +0530 Subject: [PATCH] fix: project velocity and acceleration onto 2D axes in stepAlongPlane stepAlongPlane() accepted angleRad as a third argument from its caller but silently discarded it. The 2D state.velocity and state.acceleration were synced as purely horizontal vectors (v, 0) regardless of the plane angle, which is incorrect. Fixed by accepting angleRad (defaulting to 0) and projecting the scalar plane values onto 2D axes using cos/sin, so state.velocity and state.acceleration correctly reflect the actual direction of motion along the inclined surface. --- app/(core)/physics/InclinedPlaneBody.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/(core)/physics/InclinedPlaneBody.js b/app/(core)/physics/InclinedPlaneBody.js index 0890332f..f45c0bee 100644 --- a/app/(core)/physics/InclinedPlaneBody.js +++ b/app/(core)/physics/InclinedPlaneBody.js @@ -24,7 +24,7 @@ export class InclinedPlaneBody extends PhysicsBody { /** * Physics step constrained to plane */ - stepAlongPlane(dt, netForceParallel) { + stepAlongPlane(dt, netForceParallel, angleRad = 0) { if (dt <= 0) return; // Calculate acceleration from net force @@ -36,12 +36,14 @@ export class InclinedPlaneBody extends PhysicsBody { // Update position along plane this.planeState.posAlongPlane += this.planeState.velAlongPlane * dt; - // Sync with base state for compatibility - this.state.acceleration.set(this.planeState.accAlongPlane, 0); - this.state.velocity.set(this.planeState.velAlongPlane, 0); + // Sync with base state — project scalar plane values onto 2D axes + const v = this.planeState.velAlongPlane; + const a = this.planeState.accAlongPlane; + this.state.velocity.set(v * Math.cos(angleRad), v * Math.sin(angleRad)); + this.state.acceleration.set(a * Math.cos(angleRad), a * Math.sin(angleRad)); // Update moving state - this.isMoving = Math.abs(this.planeState.velAlongPlane) > 0.001; + this.isMoving = Math.abs(v) > 0.001; } /**