Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mid height property to CapsuleShape2D/3D #93836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

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 in set_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.

doc/classes/CapsuleShape2D.xml Outdated Show resolved Hide resolved
doc/classes/CapsuleShape3D.xml Outdated Show resolved Hide resolved
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.

2 participants