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

bug: body stickToPlatform doesn't play nice with setParent #628

Open
dragoncoder047 opened this issue Mar 7, 2025 · 8 comments
Open

bug: body stickToPlatform doesn't play nice with setParent #628

dragoncoder047 opened this issue Mar 7, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@dragoncoder047
Copy link
Contributor

i think i just found a new weird bug with the way that the curPlatform interacts with the setParent function. In my game there can be objects stacked on top of each other, and when the player grabs the bottom one it is made a child of the player, and so the pos is set to (0, 0), but it is relative to the player. So the thing that was sitting on top of the player, thinks that the platform teleported to (0, 0) and moves to match, except the thing that was sitting on top isn't relative to the player, and flies off into the void. ofc I could fix this by using {stickToPlatform: false} but I need the stick to platform functionality.

the best fix might just be to use .worldPos()! in the delta computations instead of .pos in BodyComp.update(), but I haven't tested this yet.

@dragoncoder047 dragoncoder047 added the bug Something isn't working label Mar 7, 2025
@mflerackers
Copy link
Member

Couldn't body watch an onParentChanged event? worldPos is more expensive than pos, no?

@dragoncoder047
Copy link
Contributor Author

could certainly try that. the setParent code is way newer than the body stickToPlatform code so it's not surprising that the stickToPlatform code wasn't written with the parent being changed in mind.

@mflerackers
Copy link
Member

The stickToPlatform code is a bit of a hack

@mflerackers
Copy link
Member

Since you are following the platform's movement, it would make more sense to make the platform the new parent of the player, as you are basically changing the frame of reference. But I guess that would break existing things.

@dragoncoder047
Copy link
Contributor Author

The player is not standing on the platform. The object that the player picked up (and is now a child of the player) is the platform, and the thing that was sitting on that got flung into the void.

@mflerackers
Copy link
Member

Yes, but if the thing on the platform was a child of the platform, it wouldn't be affected by the player picking up the platform, it would still be relative to the platform. Now we have some hack which tries to map the motion of the platform to the things on the platform, while the thing on the platform should just have been parented. But when stickToPlatform was written, you couldn't change the parent.

@dragoncoder047
Copy link
Contributor Author

This could also be fixed by having body() monkeypatch-override the move() and moveBy() methods, so it interfaces with the velocity, and then the friction could take the relative velocity into account and drag the carried things along, and you turn it off by setting the friction to 0 on one of the bodies.

@mflerackers
Copy link
Member

That would still be a hack though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

2 participants