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 AnimatableBody sync to physics #100056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

@huwpascoe huwpascoe requested review from a team as code owners December 5, 2024 16:47
@akien-mga akien-mga added this to the 4.4 milestone Dec 5, 2024
@@ -87,9 +89,9 @@ void AnimatableBody2D::_notification(int p_what) {

case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
// Used by sync to physics, send the new transform to the physics...
Transform2D new_transform = get_global_transform();
next_transform = next_transform * last_valid_transform.affine_inverse() * get_global_transform();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my uttermost ignorance of the topic, why... why does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially, it adds the difference.

diff = global - last_valid
next = next + diff

Shorthand

next += global - last_valid

Could also write it like this

next += (-last_valid) + global

or this

next += inverse(last_valid) + global

But these are transform matrix, need to combine them with a special * operator.

next = next * inverse(last_valid) * global

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment