fix: project velocity and acceleration onto 2D axes in stepAlongPlane#316
Conversation
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.
|
Hey @TechGenius-Karan can you please explain better (maybe with a clip of the bug or idk) whats the issue you fixed |
|
Happy to clarify! Here's a concrete example of what was wrong and what the fix does. The problem in one sentence: The velocity and acceleration stored in state.velocity / state.acceleration always Concrete example — 30° incline, ball moving at 5 m/s along the plane: Before fix: After fix: Visually: Before (wrong): After (correct): Why it matters: state.velocity is what gets read when drawing velocity/acceleration vector arrows on screen, and The fix (3 lines in stepAlongPlane()): // After: Hope this clarifies your doubt better. |
|
Oh yeah all clear now! Was an easy one to understand, I'm sorry I'm so tired I feel dumb |
|
Anyway thank you for this! |
📘 Pull Request Template – PhysicsHub
Thank you for contributing to PhysicsHub!
Please complete the sections below to help us review your pull request efficiently.
🔍 Description
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.
Closes #BUG-004 (if applicable)
✅ Checklist
Before requesting a review, please ensure that you have:
npm run dev)🎨 Visual Changes (if UI-related)
IF CHANGES ARE RELATED TO SIMULATIONS PLEASE SEND A SHORT CLIP ABOUT IT
(OBLIGATORY)
📂 Type of Change
🧩 Additional Notes for Reviewers