Add mid height property to CapsuleShape2D/3D #93836
Open
+60
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a
mid_height
property to CapsuleShape2D and CapsuleShape3D, which is a wrapper for height that excludes the radiuses of the cap hemispheres. This is the height of the central cylindrical part of the capsule, and is the distance between the centers of the two hemispheres.The motivation for this PR is for improved interoperability with code that expects the mid height, specifically glTF interactivity behavior graphs, because then we can simply point the script at this property. Of course there are other challenges with mapping glTF properties to Godot ones, such as unit conversions like radians vs degrees, but capsule mid height is particularly tricky because you need to use two other properties to determine it. We could certainly solve it entirely outside of this class, but I think it would be a convenient helper property to have in core for some use cases.
As a bonus, the existence of the mid height property makes it clear that the regular height is the full height, so hopefully users would not need to check the docs if they forget what height means in the context of Godot's capsules.
I added this to CapsuleShape2D for consistency but I am only planning to use the CapsuleShape3D property myself.
I also added a few
f
suffixes to prevent calculations being done in doubles unnecessarily, and flipped the condition inset_radius
to prevent calculating an unnecessary value (haven't benchmarked, but probably slightly faster). I tested this in a minimal project and it works as expected.