godotengine / godot-proposals

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

Add boolean operations to 2D collision objects #200

Open define-private-public opened 4 years ago

define-private-public commented 4 years ago

Describe the project you are working on: This feature request stems from this forum post: https://godotforums.org/discussion/21443/is-it-possilble-to-do-boolean-operations-to-construct-collision-objects

Describe the problem or limitation you are having in your project: Same limitation from #199, I'm trying to make a Colosseum where I need to keep my objects inside of a circle. CollisionShape2D with Circle right now keeps them outside of the said circle. Manually drawing out a collision polygon with perfect curves is a pain (and not that elegant of a solution).

Describe how this feature / enhancement will help you overcome this problem or limitation: Would be a massive time saver, and much more flexible if I need to make changes in the future.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work: The diagram here is a good example of what I want: https://en.wikipedia.org/wiki/Boolean_operations_on_polygons

https://en.wikipedia.org/wiki/Constructive_solid_geometry

As for how to make a nice Godot friendly interface, I'm not quite sure.

Describe implementation detail for your proposal (in code), if possible: N/A.

If this enhancement will not be used often, can it be worked around with a few lines of script?: N/A

Is there a reason why this should be core and not an add-on in the asset library?: Super-duper useful (and semi-fundamental) for 2D game developers.

define-private-public commented 4 years ago

IIRC, the 3D part of Godot has this. Would be really neato to do this in 2D as well

Calinou commented 4 years ago

See also https://github.com/godotengine/godot/pull/28987 and https://github.com/godotengine/godot/pull/29881.

Xrayez commented 4 years ago

Does colosseum style area looks like a closed donut or does it have an entrance?

If former, then your colosseum have basically two geometric objects (instead of one): the boundary and the hole, which can be both be represented as polygons. Now, it's not really possible to clip a boundary with a hole to produce another polygon, instead you need to triangulate/decompose the boundary polygon in such a way that negates walkable area inside it, producing the collision mesh internally (which is really non-trivial task to do via script).

As @Calinou kindly linked, those geometry methods could already provide some solution to this. The clipping solution may contain both boundaries and holes which can be passed to triangulator/decomposer with holes support. But it's not exposed to editor in any way currently.

godotengine/godot#35929 would be particularly useful for this because you need to pass multiple boundary and holes for them to be clipped perfectly by a single geometry object, for more complex shapes.

Xrayez commented 3 years ago

I'm currently implementing 2D boolean operator nodes in Goost: goostengine/goost#39, feedback welcome!