Box Collider 2D
Box shape in node space.
component physics.BoxCollider2D
Try it
Box collider bounce
A box is launched toward the floor with gravity off. At Restitution 0 it stops when it hits.
Change Restitution from 0 to 1 to make the box bounce on the same contact. Reset restores the original collision.
Scene3 nodes
Scriptmain.aes
package demo
import "aego/physics"
// Begin just above the floor, moving down. Collider restitution changes the
// actual contact response; gravity is disabled so the stopped baseline holds.
script Impact {
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 |
| Size | Vec2 | (1, 1) | Width and height in units, before the node scale. |
From a script
Grow the collider together with the sprite, for a power-up.
package player
script Grow {
func Apply(factor float) {
box := node.Get<BoxCollider2D>()
box.Size = box.Size * factor
sr := node.Get<SpriteRenderer>()
sr.Size = sr.Size * factor
}
}
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.