reckfellENGINE

CapsuleShape2D

Vertical capsule: radius, total height and straight-section height.

On this page
class CapsuleShape2DReckfellSharpInherits Shape2D

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:

C#
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
# CapsuleShape2D
C#
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
# Height
C#
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
# MidHeight
C#
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
# Radius
C#
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
# GetHeight
C#
public float GetHeight();

Current total height including rounded ends; may change after assigning Radius.

Returns float

Current total height including rounded ends; may change after assigning Radius.

GetMidHeightfloat
# GetMidHeight
C#
public float GetMidHeight();

Current straight-section height: Height−2×Radius. Computed from the current dimensions.

Returns float

Current straight-section height: Height−2×Radius. Computed from the current dimensions.

GetRadiusfloat
# GetRadius
C#
public float GetRadius();

Current radius in local 2D units. Reading does not modify the shape.

Returns float

Current radius in local 2D units. Reading does not modify the shape.

SetHeightvoid
# SetHeight
C#
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.

Parameters
NameTypeDefault
heightfloat—
height

Positive finite total height including rounded ends. Shrinks Radius to half the height when needed.

SetMidHeightvoid
# SetMidHeight
C#
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.

Parameters
NameTypeDefault
midHeightfloat—
midHeight

Finite nonnegative straight-section height; the diameter is added to it. Total height must remain finite too.

SetRadiusvoid
# SetRadius
C#
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.

Parameters
NameTypeDefault
radiusfloat—
radius

New radius; use a positive finite value. On a capsule this may increase Height to the diameter.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.