CapsuleShape2D
Vertical capsule: radius, total height and straight-section height.
The capsule extends along local Y and is centered at the origin. Radius sets the rounded-end radius; width is 2×Radius. Height includes both rounded ends. MidHeight is only the straight section: Height−2×Radius. Defaults are Radius=10, Height=30 and MidHeight=10. GetRect() has position (-Radius,-Height/2) and size (2×Radius,Height).
Dimensions are linked. Increasing Radius beyond Height/2 raises Height to the diameter. Reducing Height below the diameter shrinks Radius. Therefore Radius=20 followed by Height=10 produces radius 5 and height 10; the reverse order produces radius 20 and height 40.
When radius and straight-section height are known, assign Radius first, then MidHeight. This complete executed helper validates input before creating a native resource. The caller owns the result:
using System;
using Reckfell;
public static class ShapeFactory2D
{
// The caller owns the resource. Width is twice the radius;
// middleHeight excludes the two rounded ends.
public static CapsuleShape2D Capsule(float radius, float middleHeight)
{
if (!float.IsFinite(radius) || radius <= 0)
throw new ArgumentOutOfRangeException(nameof(radius));
if (!float.IsFinite(middleHeight) || middleHeight < 0 ||
!float.IsFinite(middleHeight + 2 * radius))
throw new ArgumentOutOfRangeException(nameof(middleHeight));
var shape = new CapsuleShape2D();
shape.Radius = radius;
shape.MidHeight = middleHeight;
return shape;
}
}ShapeFactory2D.Capsule(8,24) creates width 16 and total height 40. MidHeight=0 removes the straight section. MidHeight is available in C# although not shown as an ordinary Inspector field. Repeating Radius or Height emits no Changed; repeating MidHeight does emit it.
To include the shape in the physics world, assign it to Shape on a CollisionShape2D inside CollisionObject2D. A shared resource remains shared: create separate instances for independent dimensions.
Setter order, bounds, notifications, helper validation and direct overlaps with a circle were checked. Character movement, steps, slopes, contact resolution and visual quality were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
CapsuleShape2DConstructor
public CapsuleShape2D();Creates a vertical capsule with Radius=10, Height=30 and MidHeight=10, centered at the local origin. A geometry resource, not a physics body.
Properties3
HeightProperty
public float Height { get; set; }Full height along local Y, including both rounded ends; initially 30. If the new height is below 2×Radius, radius shrinks to Height/2. Negative values are rejected. A change emits Changed; repeating the value does not. This is not the straight-section height.
MidHeightProperty
public float MidHeight { get; set; }Straight-section height excluding rounded ends: Height−2×Radius, initially 10. Assigning it preserves Radius and sets Height=MidHeight+2×Radius. Negative values are rejected; 0 removes the straight section. The setter emits Changed even for repeated values. Available in C# although not shown as an ordinary Inspector field.
RadiusProperty
public float Radius { get; set; }Rounded-end radius and half the width, initially 10. If the new value exceeds Height/2, total height increases to 2×Radius. Negative values are rejected. A change emits Changed; repeating the value does not. Radius/Height assignment order affects the result.
Methods6
GetHeightfloat
public float GetHeight();Current total height including rounded ends; may change after assigning Radius.
floatCurrent total height including rounded ends; may change after assigning Radius.
GetMidHeightfloat
public float GetMidHeight();Current straight-section height: Height−2×Radius. Computed from the current dimensions.
floatCurrent straight-section height: Height−2×Radius. Computed from the current dimensions.
GetRadiusfloat
public float GetRadius();Current radius in local 2D units. Reading does not modify the shape.
floatCurrent radius in local 2D units. Reading does not modify the shape.
SetHeightvoid
public void SetHeight(float height);Full height along local Y, including both rounded ends; initially 30. If the new height is below 2×Radius, radius shrinks to Height/2. Negative values are rejected. A change emits Changed; repeating the value does not. This is not the straight-section height.
| Name | Type | Default |
|---|---|---|
height | float | — |
heightPositive finite total height including rounded ends. Shrinks Radius to half the height when needed.
SetMidHeightvoid
public void SetMidHeight(float midHeight);Straight-section height excluding rounded ends: Height−2×Radius, initially 10. Assigning it preserves Radius and sets Height=MidHeight+2×Radius. Negative values are rejected; 0 removes the straight section. The setter emits Changed even for repeated values. Available in C# although not shown as an ordinary Inspector field.
| Name | Type | Default |
|---|---|---|
midHeight | float | — |
midHeightFinite nonnegative straight-section height; the diameter is added to it. Total height must remain finite too.
SetRadiusvoid
public void SetRadius(float radius);Rounded-end radius and half the width, initially 10. If the new value exceeds Height/2, total height increases to 2×Radius. Negative values are rejected. A change emits Changed; repeating the value does not. Radius/Height assignment order affects the result.
| Name | Type | Default |
|---|---|---|
radius | float | — |
radiusNew radius; use a positive finite value. On a capsule this may increase Height to the diameter.