Capsule Collider2D Component
The CapsuleCollider2D
class is a component in Tsar engine used to define a capsule outline to a 2D rigidbody.
There are two types of colliders: solid and sensor.
- Solid -> default collider which provides collision and other bodies with solid colliders cannot pass through it.
IsSensor
should befalse
. - Sensor -> collider which doesn't provide collision and other colliders pass through (overlap) it.
IsSensor
should betrue
.
Below is an image showing different size capsules using current Debug rendering inside Tsar. You can change collider color in Editor from Settings->Physics2D->Gizmo.
Note that if width of capsule is greater than its height, it becomes a circle with diameter = width.

Class Declaration
class CapsuleCollider2D : public Component
This class inherits from the Component
class and adds functionality related to defining shape outline of a Rigidbody for simulating 2D physics.
Public Methods
Size
Size is the width(X) and height(Y) of glm::vec2. CapsuleCollider2D stores these values in meters and when a collider is created, the scale from Transform is normally applied. If width becomes greater than height, the shape becomes circle with radius=width/2.
glm::vec2 GetSize(bool applyTransformScale = true)
Returns the size of collider from compoennt. Width(X) and Height(Y).
- applyTransformScale - should the returned size from component have applied scale, default is true.
void SetSize(const glm::vec2& size, bool applyTransformScale = true)
Change size of shape. May have overhead if not called right after initialization/construction.
- size - Units of width(X) and height(Y), sets component data regardless of applyTransform.
- applyTransform - true(applies scale), false(uses collider size only).
Offset
Offset is the local offset (relative to entity itself) that can be used to precisely adjust collider position on the body.
glm::vec3 Offset
uses X and Y for physics and Z is used only for Debug Rendering.
float OffsetRot
is local angle offset along Z-axis in degrees. Final rotation is: Rotation Z from Transform + OffsetRot
glm::vec3 GetOffset()
Returns shape local offset.
void SetOffset(const glm::vec3& offset)
Set local offset position of collider, X and Y matter for physics.
float GetOffsetRot()
Returns angle offset along Z-axis in degrees.
void SetOffsetRot(float offsetRot)
Set local angle offset of collider along Z-axis in degrees.
Properties
The CapsuleCollider2D
class exposes properties (that can also be accessed via getter and setter functions). These properties allow users to manipulate the shape properties of the object in a more intuitive manner:
float Density
Density of the shape, in kg/m².
- Get:
GetDensity()
- Set:
SetDensity(float density, bool updateMass = true)
- density - desired density in kg/m².
- updateMass - should the body mass data be updated with this shape?
float Restitution
From Physics Material. Energy conservation coefficient. 1 means perfect bounce with no energy loss, 0 means perfect absorbtion with no bounce.
- Get:
GetRestitution()
- Set:
SetRestitution(float restitution)
- restitution - should be value between [0; 1].
float Friction
From Physics Material. Friction coefficient, 0 means no friction(slippery, like ice), 1 means high friction(grippy, like rubber), values >1 are allowed.
- Get:
GetFriction()
- Set:
SetFriction(float friction)
- friction - should be non-negative value.
bool IsSensor
Is the shape sensor or not(solid)? true means no collision, false means solid collider providing collision.
Default is false.
- Get:
GetIsSensor()
- Set:
SetIsSensor(bool isTrigger)
- isTrigger - true makes shape like ghost/hollow detector, false makes shape solid.
bool EnableCollisionEvents
Should collision events be registered from this shape and trigger Enter/Exit events in scripting.
*Requires IsSensor=false
. This itself doesn't affect collisions.
- Get:
GetEnableCollisionEvents()
- Set:
SetEnableCollisionEvents(bool enableCollisionEvents)
- enableCollisionEvents - true enables event registration, false disables event registration.
bool EnableHitEvents
Should hit events be registered from this shape and trigger Enter/Exit events in scripting.
Requires IsSensor=false
and EnableCollisionEvents=true
to work. This itself doesn't affect collisions.
- Get:
GetEnableHitEvents()
- Set:
SetEnableHitEvents(bool enableHitEvents)
- enableHitEvents - true enables event registration, false disables event registration.
bool EnableSensorEvents
Should sensor events be registered from this shape and trigger Enter/Exit events in scripting.
Requires IsSensor=true
. This itself doesn't affect collisions.
- Get:
GetEnableSensorEvents()
- Set:
SetEnableSensorEvents(bool enableSensorEvents)
- enableSensorEvents - true enables event registration, false disables event registration.