godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Add fluid simulation to the 2D physics engine #116

Open nezvers opened 4 years ago

nezvers commented 4 years ago

Google has made an open-sourced extension on Box2d. Gamemaker already has implemented it and I think Godot community will only benefit with this new tool.

Describe the problem or limitation you are having in your project: I haven't had luck with simulating liquid on my own.

Describe how this feature/enhancement will help you overcome this problem or limitation: A convenient way to create good looking liquid simulation.

Show a mock-up screenshots/video or a flow diagram explaining how your proposal will work: Examples are shown in Google's own GitHub repository - https://google.github.io/liquidfun/

Describe implementation detail for your proposal (in code), if possible: I think it can be used as Rigidbody2D mode and as standalone node (same as Kinematicbody2D and Staticbody2d)

Is there a reason why this should be core and not an add-on in the asset library?: It is part of the same physics system that's already supported by Godot.

groud commented 4 years ago

It is part of the same physics system thatš already supported by Godot

Godot does not use Box2D. It uses a custom physics engine.

Xrayez commented 4 years ago

There was rumors to include Box2D in Godot as a physics backend but lead developer expressed concern whether Box2D could provide what Godot's physics requires: https://github.com/godotengine/godot/pull/10013#issuecomment-320449871.

Though I think the proposal is not about adding Box2D but implementing something similar instead.

There was mentions about MODE_BODY_SOFT in engine's source code for 2D physics, but I can't seem to find them anymore. But then again I'm not sure whether liquid could be implemented as a soft body.

Sslaxx commented 4 years ago

Godot does use at least part of Box2D for its 2D physics implementation. Is that part enough to implement Liquid Fun, or would it be worth either increasing the amount of Box2D code used or switching to Box2D altogether?

groud commented 4 years ago

Godot does use at least part of Box2D for its 2D physics implementation.

No. What makes you think that ? There nothing from Box2D in Godot (but one file included in Bullet apparently).

rainerdeyke commented 4 years ago

Sslaxx is probably referring to the code in thirdparty/b2d_convexdecomp/.

groud commented 4 years ago

Sslaxx is probably referring to the code in thirdparty/b2d_convexdecomp/.

Ah you are right, we use 3 files for decomposing convex shapes. But nothing from the Box2D physics engine is used in fact.

Is that part enough to implement Liquid Fun,

So no. And it is unlikely we add the Box2D physics engine only for supporting this.

Simulating liquids should be a good feature though, but not with Box2D. :)

arkology commented 4 years ago

+1 for having such feature. I saw fluid module somewhere, but it would be great to have build-in fluid simulation.

nezvers commented 4 years ago

My bad then. Seeing that pretty much all functions are all the same for RigidBody2D as in Box2D (except naming), I was under the assumption it's Box2D physics. Still, I wish to see fluid simulation someday in Godot.

Jummit commented 4 years ago

It is part of the same physics system that's already supported by Godot.

This isn't valid anymore.

Is there a reason why this should be core and not an add-on in the asset library?

The answer to is probably no, since fluid sims are (at least from my experience) not that important to most developers.

arkology commented 4 years ago

since fluid sims are (at least from my experience) not that important to most developers.

As well as SoftBody node...

Jummit commented 4 years ago

since fluid sims are (at least from my experience) not that important to most developers.

As well as SoftBody node...

True :D I think this can stay open, because I have a feeling that if someone is passionate enough to implement it and make a PR, it will get merged. Thanks for the heads up!

Ughuuu commented 1 year ago

If someone is interested, I made a SoftBody2D plugin: Ughuuu/godot-softbody2d. You can read in the repo how it works. It's also on asset store.

Also, about the box2D integration, you can try this plugin (wip) here: godot-box2d. It's also on asset store as well.

If anything a step in the direction of water simulation (probably as a plugin).