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

The position of a rigid-body represents its location (translation) in 2D or 3D world-space, as well as its orientation (rotation).
<rapier>Its translational part is represented as a vector and its rotational part as an unit quaternion (in 3D) or a unit complex
number (in 2D). Both are combined into a pose (the `Pose` type)</rapier><bevy> stored in the standard Bevy `Transform` component</bevy>.

The position of a rigid-body can be set when creating it. It can also be set after
its creation as illustrated below.

:::warning
Directly changing the position of a rigid-body is equivalent to teleporting it: this is a not a
physically realistic action! Teleporting a dynamic or kinematic bodies may result in odd behaviors
especially if it teleports into a space occupied by other objects. For dynamic bodies, [forces,
impulses](./rigid_bodies.mdx#forces-and-impulses), or [velocity modification](./rigid_bodies.mdx#velocity) should be preferred.
For kinematic bodies, see the discussion after the examples below.
:::

<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='Position1' />
```
```rust
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Position2' />
```

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

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

  </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='Position1' />
```
```rust
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Position2' />
```

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

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

  </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='Position1' />
```
```js
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Position2' />
```

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

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

  </TabItem>
</Tabs>

</js>

In order to move a dynamic rigid-body it is strongly discouraged to set its position directly as it
may results in weird behaviors: it's as if the rigid-body teleports itself, which is a non-physical behavior. For dynamic
bodies, it is recommended to either set its [velocity](./rigid_bodies.mdx#velocity) or to apply [forces or impulses](./rigid_bodies.mdx#forces-and-impulses).

<rapier>

For **velocity-based** kinematic bodies, it is recommended to set its velocity instead of setting its position directly.
For **position-based** kinematic bodies, it is recommended to use the special methods:
- `RigidBody::set_next_kinematic_rotation`
- `RigidBody::set_next_kinematic_translation`

These methods will let the physics pipeline compute the fictitious velocity of the position-based kinematic body for more realistic
interactions with other rigid-bodies. These methods won't immediately modify the position of the kinematic body itself.
The position of the kinematic body will be automatically set to these values during the next physics pipeline update.

</rapier>
<bevy>

For **velocity-based** kinematic bodies, it is recommended to set its velocity instead of setting its position directly.
For **position-based** kinematic bodies, it is recommended to modify its `Transform` (changing its velocity won’t have
any effect). This will let the physics engine compute the fictitious velocity of the kinematic body for more
realistic intersections with other rigid-bodies.

</bevy>
<js>

For **velocity-based** kinematic bodies, it is recommended to set its velocity instead of setting its position directly.
For **position-based** kinematic bodies, it is recommended to use the special methods:
- `RigidBody.setNextKinematicRotation`
- `RigidBody.setNextKinematicTranslation`

These methods will let the physics pipeline compute the fictitious velocity of the position-based kinematic body for more realistic
interactions with other rigid-bodies. These methods won't immediately modify the position of the kinematic body itself.
The position of the kinematic body will be automatically set to these values during the next physics pipeline update.

</js>
