import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

The velocity of a dynamic rigid-body controls how fast it is moving in time. The velocity is applied at the **center-of-mass**
of the rigid-body, and is composed of two independent parts:
1. The **linear velocity** is specified as a vector representing the direction and magnitude of the movement.
2. In 3D, the **angular velocity** is given as a vector representing the rotation
   axis multiplied by the rotation angular speed in `rad/s` (axis-angle representation). In 2D, the **angular velocity** is
   given as a real representing the angular speed in `rad/s`.

:::info
The velocity is only relevant to **dynamic** rigid-bodies. It has no effect on fixed rigid-bodies, and the
velocity of kinematic rigid-bodies are automatically computed at each timestep based on their next kinematic
positions.
:::

The velocity of a rigid-body is automatically updated by the physics pipeline after taking forces, contacts,
and joints into account. It can be set when the rigid-body is created or after its creation:

<rapier>

<Tabs
groupId="dim"
defaultValue="2D"
values={[
{label: 'Example 2D', value: '2D'},
{label: 'Example 3D', value: '3D'},
]}>
<TabItem value="2D">

```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Velocity1' />
```
```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Velocity2' />
```

  </TabItem>
  <TabItem value="3D">

```rust
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Velocity1' />
```
```rust
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Velocity2' />
```

  </TabItem>
</Tabs>

</rapier>

<bevy>

<Tabs
groupId="dim"
defaultValue="2D"
values={[
{label: 'Example 2D', value: '2D'},
{label: 'Example 3D', value: '3D'},
]}>
<TabItem value="2D">

```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Velocity1' />
```
```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Velocity2' />
```

  </TabItem>
  <TabItem value="3D">

```rust
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Velocity1' />
```
```rust
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Velocity2' />
```

  </TabItem>
</Tabs>

</bevy>
<js>

<Tabs
groupId="dim"
defaultValue="2D"
values={[
{label: 'Example 2D', value: '2D'},
{label: 'Example 3D', value: '3D'},
]}>
<TabItem value="2D">

```js
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Velocity1' />
```
```js
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Velocity2' />
```

  </TabItem>
  <TabItem value="3D">

```js
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Velocity1' />
```
```js
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Velocity2' />
```

  </TabItem>
</Tabs>

</js>

Alternatively, the velocity of a dynamic rigid-body can be altered indirectly by
[applying a force or an impulse](./rigid_bodies.mdx#forces-and-impulses).
