Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply same delta from position to previous position when setParts runs #1074

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tylerfurtwangler
Copy link

Problem

Currently when setParts is run, it sets the position and positionPrev to the new total parts centre values. This is fine when the body is stable/constant when being set, however for actively moving objects this will cause the new body to have no delta between positions.

This factors in when calculating the new velocity during update: https://github.com/tylerfurtwangler/matter-js/blob/master/src/body/Body.js#L638

Fix

This change uses the existing body positionPrev and position values to come up with a delta to apply to the body to keep the previous relative positions the same during a setParts call.

Testing Notes

I am unfamiliar with the process, and can close this PR if more is required for the main repo. This can be seen by calling setParts on a falling object, the object "stalls" midair as it no longer has a positionPrev delta from position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant