Capsule Collider 2D
Capsule along the local X axis; Length is the full extent including the caps.
component physics.CapsuleCollider2D
Try it
Capsule collider bounce
The visible horizontal capsule moves toward the floor with gravity off. At Restitution 0 it stops on contact.
Change Restitution from 0 to 1 to make the same collision bounce. Reset restores the original contact.
Scene5 nodes
Scriptmain.aes
package demo
import "aego/physics"
// The visible capsule matches the collider's dimensions. It strikes the
// floor at a fixed speed so Restitution changes the real contact response.
script CapsuleImpact {
func Ready() {
body := node.Get<Body2D>()
body.SetVelocity(Vec2{0, 15})
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Offset | Vec2 | (0, 0) | Position of the shape in node space. |
| Is Trigger | bool | false | Detects overlaps and sends trigger events without pushing bodies apart. |
| Friction | float | 0.6 | Resistance to sliding along other shapes; 0 is ice. Two shapes use the square root of the product. ≥ 0 |
| Restitution | float | 0 | Bounciness: 0 stops on impact, 1 bounces back at the same speed. Two shapes use the larger value. ≥ 0 |
| Density | float | 1 | Mass per square unit; gives the body its mass when Mass Mode is auto. ≥ 0 |
| Length | float | 1 | Full length along the local X axis, caps included. ≥ 0 |
| Radius | float | 0.25 | Radius of the caps and half the thickness. ≥ 0 |
From a script
Crouch by shortening the capsule.
package player
import "aego/input"
script Crouch {
var Standing float = 1
var Crouching float = 0.4
func Update(dt float) {
capsule := node.Get<CapsuleCollider2D>()
capsule.Length = Standing
if input.Held("Crouch") {
capsule.Length = Crouching
}
}
}
Script events
Scripts on a node with this component receive these events from the Physics 2D module.
OnCollisionEnter— Runs after the physics step in which this body started touching other.OnCollisionExit— Runs when the bodies stop touching, including when one of them is destroyed or disabled. Contact.Point is the last known point.OnCollisionStay— Runs after every later physics step while the bodies keep touching. It costs nothing when no script declares it.OnTriggerEnter— Runs when other's collider entered a trigger of this body, or this body entered other's trigger.OnTriggerExit— Runs when the overlap with a trigger ends.
Related guides
- Components These components make a node part of the simulation.
- Physics 2D Aego simulates 2D rigid bodies with its own solver.