-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
AnimatableBody2D doesn't work when parent moves #58269
Comments
I tried to figure out what's the problem, and I believe that in physics_body_2d.cpp it subscribes to local transform changing, not global, so moving parent doesn't trigger the update. I'm not familiar with building and poking the source, so I can't try to fix it, but I hope this is pointing to the right direction :) |
I think this bug is related with: #54915 The workaround for now is to use a |
I made few more tests and can confirm that this is not directly related to PathFollow2D, but any case, where AnimatableBody's parent is moving. Also, it occurs only for AnimatableBody, other PhysicsBodies work as intended. |
I tested this on AnimatableBody3D, and the same issue occurs there as well. Likely the solution to both will be the same, so I won't open a second issue for it. |
when using either the remote transform or other workarounds like setting the body's transform to Transform2d.IDENTITY, the body lags behind the parent by a frame, so it's still not a great situation. hoping someone can look into a true fix |
I tried looking into this again, thinking third time's the charm, but it seems I'm not one step closer to solution. |
I tried to move to the global transform notification too. All of this seems to be a lot of hacks to make the render sync with the physics. I found a workaround, but not good enough to be merged. There is no such simple solution for this without something like #76252 or rewriting everything from scratch. |
Hit this as well, appreciate that there's a workaround, but it's not intuitive at all for figuring out how to make moving platforms or enemies that just go back-and-forth easily with a path. |
I had trouble using the Path2D> PathFollow2D > RemoteTransform for my setup. The animatablebody always pushed off my player. I switched to just each physics_process updating the position to the position of the Pathfollow for my animatablebody, as I had a feeling somewhere there was something not being updated at physics time. It seemingly worked. If this is correct, perhaps RemoteTransform also needs an "synch with physics" option? (I am hypothesizing without any knowledge of the C side of things) |
This seems to still happen on 4.2.1 stable |
This issue only happens when "sync to physics" is set. My feeling (shared by others in Github) is that "sync to physics" is an ugly hack. The documentation says this setting is needed when the object is animated from an AnimationPlayer but there's already a I think that a better solution would be to sync the originator of the movement instead of the moved object. So the solution could be disabling "sync to physics" and setting I've tried in the test project and it improves significantly the jittering and fixes the collisions, although there's still a 1-pixel gap between the rigid body and the platform. The AnimatableBody2D updated from AnimationPlayer works perfectly so there's must be some other issue creeping here. So maybe the solution is simply ignoring/removing "sync to physics" here and instead sync the code moving the object. When using a Tween, setting the Edit: It seems |
Ive created a PR that seems to fix this issue although it's as hacky as it already was. It should be better tested to see if it doesn't break anything in some cases. |
Using |
a temporary workaround is the following piece of code: # in a _*process() method
global_position = global_position |
What is this supposed to fix? Is this to be used in conjunction with the RemoteTransform, or instead of? |
no, but this is used in the script attached to the animated body being a child of the path follower you are using. |
Just encountered this issue in |
I still seems like thats the case in Edit: Disabling |
@berarma I encountered this issue myself and after some testing, digging into the code and asking around on forum about what is the actual idea behind Hypothetically this could be solved another way - by running another round of adjustments for some specific objects in the same physics frame. So we could stick character to the platform if we miscalculated its future position by small margin in first iteration. But it would be much complicated because we would have to actually care about predicting next position of platform, be ready for mistakes and additional adjustments. With |
There's two points here:
|
Godot version
v4.0.alpha2.official [79077e6]
System information
Windows 10
Issue description
When animating a moving AnimatableBody2D platform with Path2D, it's physical location doesn't seem to update. Graphically everything seems fine.
Edit: Problem occurs, if AnimatableBody2D's parent moves, ie. node's local transform stays the same, but global transform changes.
Steps to reproduce
Using following setup:
The example project has 2 platforms. The left one is updated with AnimationPlayer, other with Path2DFollow. The left one works as expected, but the right one demonstrates the bug. Just run and see, rigidbody box on the right is floating in the air. Interestingly, collision shape draws in the right place.
Minimal reproduction project
AnimatableBodyTest.zip
The text was updated successfully, but these errors were encountered: