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

Box2dPhysicsNodes and fixtures should still work in sub-scenes. #26

Closed
jordo opened this issue Dec 9, 2020 · 13 comments
Closed

Box2dPhysicsNodes and fixtures should still work in sub-scenes. #26

jordo opened this issue Dec 9, 2020 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@jordo
Copy link
Collaborator

jordo commented Dec 9, 2020

during porting of my project, I discovered that obviously physics bodies and fixtures need to be supported in sub-scenes. i.e, the scene doesn't hold a world node, but is attached to another node which contains the world. In the screenshot below GameData scene is included in another scene (which contains the box2d world).

Screen Shot 2020-12-08 at 8 36 18 PM

Going to investigate how to support this.

@jordo jordo self-assigned this Dec 9, 2020
@briansemrau
Copy link
Owner

This seems to be the primary folly of using a node to represent the physics space. Godot doesn't have this issue because it uses a physics server singleton.

Having the world as a singleton may be the only way to resolve this. We can keep Box2DWorld as a node to create spaces other than the singleton.

I believe the code to look at is https://github.com/briansemrau/godot_box2d/blob/4.0/scene/2d/box2d_physics_body.cpp#L147 (as well as in Fixture and Joint)

@briansemrau
Copy link
Owner

My initial guess at a solution would be to make a modification to look for the singleton world in case one is not found in the scene tree.

@jordo
Copy link
Collaborator Author

jordo commented Dec 9, 2020

I dunno, i'm not 100% sure about it. I'm not a huge fan of singletons, and think there's a chance we don't need the world to do body and fixture setup.

We could also default to having at least a global world available at the root, if you never add another one. Going to investigate further, but you could be right.

@jordo
Copy link
Collaborator Author

jordo commented Dec 9, 2020

IIRC The 'real root' in godot, is kinda above what you see above the scene tree (there's kinda one global root that loads scenes underneath it). I think that's the case. If that is the case, we can keep the 'World' lookup code the same (traverse up the tree until you find a world)

@jordo
Copy link
Collaborator Author

jordo commented Dec 10, 2020

Alright, this should be working with #31

@briansemrau
Copy link
Owner

Does this issue include the scope of running sub-scenes, even if just for testing? The current PR seems to make things better in the editor, but is limited to that.

@jordo
Copy link
Collaborator Author

jordo commented Dec 10, 2020

sub-scenes should work, at least they do in my test project. I've got the body nodes in subscenes below my world

Screen Shot 2020-12-09 at 10 04 30 PM

@jordo
Copy link
Collaborator Author

jordo commented Dec 10, 2020

GameData looks like this:

Screen Shot 2020-12-09 at 10 05 45 PM

I still like the warnings, cause it still give the user a warning that they need to know what they are doing for this to work

@briansemrau
Copy link
Owner

If you run this sub-scene, however, it won't work, right? Because there is no b2world

@jordo
Copy link
Collaborator Author

jordo commented Dec 10, 2020

ya, that's correct. OK, i see what you are saying now.

@jordo
Copy link
Collaborator Author

jordo commented Dec 10, 2020

So hmm, i feel like that is OK. If users set things up like this they should know what they are doing.

@briansemrau
Copy link
Owner

At least the warnings make it very clear.
It's possible this will come up as an issue in the future, but it'll likely be handled when all the b2 stuff is put into a server. Topic for the future.

@briansemrau briansemrau added the bug Something isn't working label Dec 10, 2020
@briansemrau
Copy link
Owner

closing with #32 as followup to the discussion had

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
None yet
Development

No branches or pull requests

2 participants