matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

Body.update doesn't scale time correctly

Open tehbiga opened this issue 1 year ago • 2 comments

When setting the engine's timescale to zero, 0.00 bodies that already have velocity will continue with their velocity nearly constant (depending on scale).

Digging into Body.js I noticed you are applying force/acceleration properly scaled by the timescale set, but you are still taking velocity as is and applying it to the position without scaling.

I easily tested this by stopping time, moving a body into the air above a platform, then toggling the timescale between 1.00 and 0.00. Once the body was moving it would not slow down or stop when I "paused" time.

tehbiga avatar Mar 28 '23 15:03 tehbiga

Just noticed setting the timescale to zero also causes the body to lose it's velocity entirely because it is cleared to zero once the correction* is set to zero.

Edit: I meant correction

tehbiga avatar Mar 28 '23 15:03 tehbiga

Last comment, but I'm also not sure why the body parts vertices are being permanently modified instead of used as relative offsets from the root body position and angle. It makes this significantly more difficult to correct as well as rely on the shape data for other operations if it's constantly being modified. And why are times in milliseconds?

Unfortunately noticing quite a lot is off with this library after sinking a ton of hours into a project and I'm not sure if it will work for my purposes. I appreciate your work and wish you luck in fixing things.

tehbiga avatar Mar 28 '23 15:03 tehbiga