# Rigid Body 2D

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

```
component physics.Body2D
```

Simulates the node as a rigid body. Colliders on the node and its children form its shape.

## From a script

Run with the `Move` action, jump with an impulse and read the velocity back; the body's own fields stay editable from the script.

```aes check
package player

import "aego/input"

script Runner {
    var Speed float = 6
    var Jump Vec2 = Vec2{0, -6}

    func Update(dt float) {
        body := node.Get<Body2D>()
        dir := input.Axis("Move")
        body.SetVelocity(Vec2{dir * Speed, body.Velocity.Y})
        if input.Pressed("Jump") {
            body.ApplyImpulse(Jump * body.Mass())
        }
        body.GravityScale = 1
        if body.Velocity.Y > 0 {
            body.GravityScale = 2
        }
    }
}
```

## Fields

| Name | Script name | Type | Default | Description |
|---|---|---|---|---|
| Type | `Type` | `enum` | `dynamic` | static never moves, kinematic moves by velocity, dynamic reacts to forces and contacts. |
| Mass Mode | `MassMode` | `enum` | `auto` | auto takes the mass from collider density, override uses Mass. |
| Mass | `Mass` | `float` | `0` | Mass in kilograms when Mass Mode is override. |
| Gravity Scale | `GravityScale` | `float` | `1` | Multiplier of the project gravity for this body; 0 makes it float. |
| Linear Damping | `LinearDamping` | `float` | `0` | Slows the movement every step, like air resistance; 0 keeps the speed. |
| Angular Damping | `AngularDamping` | `float` | `0` | Slows the rotation every step; 0 keeps spinning. |
| Fixed Rotation | `FixedRotation` | `bool` | `false` | Keeps the body upright: contacts and torque never rotate it. |
| Bullet | `Bullet` | `bool` | `false` | Continuous collision against other dynamic bodies, so a fast body cannot pass through them. Costs more. |
| Allow Sleep | `AllowSleep` | `bool` | `true` | Lets the body sleep after it comes to rest, which saves time; contacts and scripts wake it. |
| Interpolate | `Interpolate` | `bool` | `false` | Draws the body between physics steps for smooth motion; scripts still see the exact pose. |
| Layer | `Layer` | `layer` | `0` | Collision layer, see Project Settings → Physics. |
| Mask | `Mask` | `layer mask` | `-1` | Layers this body collides with. |
| Velocity | `Velocity` | `Vec2` | `(0, 0)` | Runtime state. Velocity in units per second. |
| Angular Velocity | `AngularVelocity` | `float` | `0` | Runtime state. Rotation speed in radians per second. |
| Awake | `Awake` | `bool` | `false` | Runtime state. Whether the body is simulated this step or sleeping. |

## ApplyForce

```
func (Body2D) ApplyForce(force Vec2)
```

Pushes the body's center of mass during the next physics step. Call it from FixedUpdate.

## ApplyForceAt

```
func (Body2D) ApplyForceAt(force Vec2, point Vec2)
```

Pushes the body at a world point, which also spins it.

## ApplyImpulse

```
func (Body2D) ApplyImpulse(impulse Vec2)
```

Changes the velocity at once, scaled by mass.

## ApplyImpulseAt

```
func (Body2D) ApplyImpulseAt(impulse Vec2, point Vec2)
```

Applies an impulse at a world point.

## ApplyTorque

```
func (Body2D) ApplyTorque(torque float)
```

Spins the body during the next physics step.

## Mass()

```
func (Body2D) Mass() float
```

Returns the mass computed from the colliders or the override.

## MoveTo

```
func (Body2D) MoveTo(position Vec2, angle float)
```

Drives a kinematic body to the pose by the end of the next physics step, pushing dynamic bodies on the way. Call it from FixedUpdate.

## SetAngularVelocity

```
func (Body2D) SetAngularVelocity(velocity float)
```

Sets the spin in radians per second.

## SetVelocity

```
func (Body2D) SetVelocity(velocity Vec2)
```

Sets the linear velocity in units per second.

## Sleep

```
func (Body2D) Sleep()
```

Stops the body until something touches it.

## Teleport

```
func (Body2D) Teleport(position Vec2, angle float)
```

Moves the body to a world pose without sweeping, keeping its velocity.

## WakeUp

```
func (Body2D) WakeUp()
```

Makes a sleeping body simulate again.
