X Tutup
Skip to content

Add Tapered collision shapes #116707

Open
Moddingear wants to merge 2 commits intogodotengine:masterfrom
Moddingear:tapered_capsules
Open

Add Tapered collision shapes #116707
Moddingear wants to merge 2 commits intogodotengine:masterfrom
Moddingear:tapered_capsules

Conversation

@Moddingear
Copy link

This is the continuation of #109009

I've fixed the mesh generation of the tapered capsule, and right now am looking at also adding tapered cylinders.

@Moddingear
Copy link
Author

Moddingear commented Feb 24, 2026

Here is a video demo:

Screencast.From.2026-02-24.14-24-54.mp4

The UVs on the top of the tapered cylinder aren't quite correct yet

@Moddingear
Copy link
Author

Moddingear commented Feb 24, 2026

godotengine/godot-proposals#610 is implemented by this PR

Just to clarify : I haven't yet checked the physics in game, there may be a mismatch between what's seen and what's collided with

@Moddingear
Copy link
Author

sorry about the wrong styles, I hadn't setup everything to have it run automatically, this is my first contrib...

@Moddingear
Copy link
Author

For completeness: this also addresses the original proposal, godotengine/godot-proposals#12875

@Moddingear Moddingear marked this pull request as draft February 25, 2026 14:07
@Moddingear
Copy link
Author

Physics have been made and tested to work with both Godot physics server (using regular non-tapered variants) and Jolt

tapered_physics.mp4

@Moddingear Moddingear marked this pull request as ready for review February 25, 2026 14:43
@fire fire requested a review from aaronfranke February 25, 2026 15:51
@Moddingear
Copy link
Author

I'll note here that a lot of the code between the tapered Cylinder and tapered Capsule is very similar, maybe it could be merged into a single parent class?

Also, I haven't made icons for the meshes or the shapes. I tried to have a go at it, but in the end it was programmer art...

Finally, maybe there could be a button to convert non-tapered cylinder/capsules into their tapered variants and vice-versa?

@aaronfranke
Copy link
Member

@Moddingear Please run --doctool after compiling Godot to update the documentation automatically.

Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

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

Looks pretty good from my perspective. Needs these property info changes, and a rebase+squash, and approval from physics folks.

@Moddingear Moddingear force-pushed the tapered_capsules branch 2 times, most recently from 02e46a7 to 0ab802f Compare February 26, 2026 17:26
@Moddingear
Copy link
Author

I did the squash+rebase, but I kept the original commit from #109009 to keep their contribution

@Moddingear
Copy link
Author

Last change is so that the tapered capsule, both mesh and collision, correctly handle being turned into spheres. There was a superfluous test to avoid that, but Jolt actually handles the case just fine...

@aaronfranke aaronfranke removed request for a team March 7, 2026 08:39
@Moddingear
Copy link
Author

I'm having a rebase issue, will undraft when fixed

Comment on lines +41 to +42
//This condition isn't necessary, as Jolt handles the case where the capsule becomes a sphere
//ERR_FAIL_COND_V_MSG(mid_height < Math::abs(radius_top - radius_bottom), nullptr, vformat("Failed to build Jolt Physics tapered capsule shape with %s. Its mid_height must be at least the absolute value of the difference of its radii. This shape belongs to %s.", to_string(), _owners_to_string()));
Copy link
Member

@fire fire Mar 7, 2026

Choose a reason for hiding this comment

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

We tend to remove code that isn't used. Not merge blocking.

Copy link
Author

@Moddingear Moddingear Mar 7, 2026

Choose a reason for hiding this comment

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

Yeah, I left it since someone might think that this case needs to be handled. I can remove that but doing a squash would invalidate the approval from @jrouwe

Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that commented out code too, but I think it's instructive as it is a tempting condition to add

@TheCogster409
Copy link

When testing this I have found that for these tapered shapes, including the mesh instances, you can't make one side have a radius of 0. It is set to 0.001, not true 0. The only shape that can be truly 0 is the built in cylinder mesh instance which can already be tapered.

Idk if this is intentional or a bug.

@fire
Copy link
Member

fire commented Mar 8, 2026

That is to align with https://github.com/eoineoineoin/glTF_Physics/tree/master/extensions/2.0/Khronos/KHR_implicit_shapes#gltf-schema-updates standards

@Moddingear
Copy link
Author

Moddingear commented Mar 8, 2026

@TheCogster409 In the case of the shapes, Jolt explicitely requires the shapes to have radii greater than 0 (Maybe this could be relaxed ?).

But I do believe that it can be handled better, so i'm going to compare with CMP_EPSILON for the shapes, and allow the mesh to reach 0 value, and when it does, optimize the geometry on the end with 0 radius, like the cylinder does currently

@fire
Copy link
Member

fire commented Mar 8, 2026

When you say a conic, do you mean like an open top like a funnel?
image

This causes problems for both physics and csg as it violates the manifold definition.

@Moddingear
Copy link
Author

In this instance, I think conic is just the case where one radius is zero

Co-authored-by: Aaron Franke <arnfranke@yahoo.com>
@jrouwe
Copy link
Contributor

jrouwe commented Mar 9, 2026

When testing this I have found that for these tapered shapes, including the mesh instances, you can't make one side have a radius of 0. It is set to 0.001, not true 0. The only shape that can be truly 0 is the built in cylinder mesh instance which can already be tapered.

Tapered capsule shape indeed doesn't accept 0 as top or bottom (prevents having to check for div by zero), but the tapered cylinder shape does.

@Moddingear
Copy link
Author

@jrouwe I've allowed 0-radius cylinders in the latest version

@AThousandShips I've rename radius_top and radius_bottom to top_radius and bottom_radius everywhere in the new files that are user facing, but not in the Physics server as it's new and can be aligned to Khronos standards.

The code to generate the vertical lines on the capsule collider was thoroughly documented so it's more understandable.

Also, now the tapered capsule generated mesh handles 0-radius ends.

@AThousandShips
Copy link
Member

Just needs the code readability fixed, none of the implicit conversions

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Style and documentation look good! Haven't tested the functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

X Tutup