Collision generation and workflow improvements#194
Collision generation and workflow improvements#194limbonaut merged 5 commits intoSirRamEsq:masterfrom
Conversation
They were soft-limits anyway, it was just confusing.
limbonaut
left a comment
There was a problem hiding this comment.
Looks promising! Love the tool abstraction idea: way more maintainable in the long run. Got a few suggestions, and still need to review the last commit. And I'd like to do some monkey testing with my project in the editor.
I think it would be helpful if we could keep some changes as separate PRs in the future. Some of these don’t seem to be related to each other.
Yeah, I'm sorry, I got a bit lazy there 😅 |
c81d29a to
674fb4e
Compare
The previous behavior created a StaticBody2D and an invisible child CollisionPolygon2D, then also moved the shape to be a child of the StaticBody2D. StaticBody2D |- CollisionPolygon |- Shape This behavior was pretty useless in real world projects and caused confusion among new users (Godot and/or SS2D). - People thought this hierarchy is mandatory and were irritated how inflexible it is - In larger projects you often do not use bare StaticBodies but reusable scenes that store more information about the body, e.g. collision layers, terrain type, additional nodes, etc. - It might be desirable to put multiple colliders into the same StaticBody or not to use StaticBody2D at all but CharacterBody2D or Area2D instead. For this reason, the collision tool was reworked to generate only a CollisionPolygon2D and add it as sibling. This behavior is more straight forward and grants users the flexibility to use it however they want without having to partially undo the generated hierarchy (or being confused about it). Additionally, a "Collision Generation Options" dialog was added where the parent for newly created CollisionPolygons can be set. If unset or not found, the node is added as sibling to the shape. The path can be specified as a regular node path or as group name. This feature is useful to group all Colliders under a single StaticBody2D without moving it manually. Finally, this patch introduces SS2D_EditorTool as a base class for editor tools with the goal of moving tool code out of plugin.gd. The Collision Tool is now implemented in SS2D_CollisionEditorTool.
- Implement "Fast" collision generation method for open shapes. Previously this existed only for closed shapes. - Add option to generate hollow collisions, i.e. only edge collisions for closed shapes. Closes SirRamEsq#110. - Apply collision_offset and collision_size in fast collision generation - Move collision generation code into a separate script - Rename collision generation methods - "Fast" is now "Default". - "Precise" is now "Legacy" because it's now obsolete and offers no real benefits besides backwards compatibility. - Add example scene to demonstrate different collision methods
1f2a5c9 to
3a74b3f
Compare
|
Updated, squashed and ready. |
|
LGTM, sorry for the delay! The formulas are all good now, and I really appreciate your comments on that complex math area. I’ve tested the branch in my project, and it's working great! The hollow collision feature is a nice addition too. Let’s merge this! |
This started out with a small idea to use
Geometry2D.offset_polyline()to generate collisions for open shapes.But then edge cases and the feature creep appeared and it grew into something much larger :D
This PR improves collision generation and makes the old mesh based approach pretty much obsolete.
It adds faster collision generation for open shapes and introduces hollow collision generation for closed shapes, which solves #110.
collision_offsetandcollision_sizewill now be correctly applied as well.The performance improvement is around 6x faster (0.05ms vs 0.3 ms on a rather simple test scene) than the old mesh based approach.
I also added a
collisions.tscnexample that demonstrates the different collision methods on closed and open shapes.I also reworked the Collision Tool to be more useful.
It now only creates a
CollisionPolygon2D. There is also a new setting to specify under which node the polygon should be added. This allows having a singleStaticBody2Dfor example and automatically adding all new collisions there.Below is a sloppy demo video.
Finally, I noticed that the recent baked-shapes update introduced VCS noise by frequently creating new resource instances which causes new IDs to be assigned and thus changes to the scene file even though the content itself did not change.I fixed this by reusing existing
SS2D_Meshinstances and getting rid ofSS2D_VertexProperties.Moved into separate PR.
Details to all changes are in the commit messages as usual.
After this gets merged, I'm going to create a new release.
Collision Tool demo
simplescreenrecorder-2025-07-13_17.41.21.mp4