Skip to content

Collision generation and workflow improvements#194

Merged
limbonaut merged 5 commits intoSirRamEsq:masterfrom
mphe:collision_improvements
Aug 25, 2025
Merged

Collision generation and workflow improvements#194
limbonaut merged 5 commits intoSirRamEsq:masterfrom
mphe:collision_improvements

Conversation

@mphe
Copy link
Collaborator

@mphe mphe commented Jul 31, 2025

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_offset and collision_size will 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.tscn example 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 single StaticBody2D for 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_Mesh instances and getting rid of SS2D_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

@mphe mphe requested a review from limbonaut July 31, 2025 20:57
Copy link
Collaborator

@limbonaut limbonaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mphe
Copy link
Collaborator Author

mphe commented Aug 10, 2025

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 😅
I keep the collision stuff here and split the other stuff in separate PRs.

@mphe mphe force-pushed the collision_improvements branch from c81d29a to 674fb4e Compare August 10, 2025 13:22
@mphe mphe changed the title Collision generation improvements and VCS noise fixes Collision generation and workflow improvements Aug 10, 2025
mphe added 3 commits August 12, 2025 20:50
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
@mphe mphe force-pushed the collision_improvements branch from 1f2a5c9 to 3a74b3f Compare August 12, 2025 18:51
@mphe
Copy link
Collaborator Author

mphe commented Aug 12, 2025

Updated, squashed and ready.

@limbonaut
Copy link
Collaborator

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!

@limbonaut limbonaut merged commit 5fbb7fd into SirRamEsq:master Aug 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants