---
url: /api/kiln/physics/classes/PhysicsState.md
---
[Kiln API](../../../index.md) / [kiln/physics](../index.md) / PhysicsState

# Class: PhysicsState

The Rapier world plus Kiln's entity mapping. Use `res.mut(Physics)` for impulses and raycasts.

## Constructors

### Constructor

```ts
new PhysicsState(
   rapier, 
   world, 
   is2D
): PhysicsState;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `rapier` | `any` |
| `world` | `any` |
| `is2D` | `boolean` |

#### Returns

`PhysicsState`

## Properties

### bodies

```ts
readonly bodies: Map<Entity, Created>;
```

***

### colliderOwner

```ts
readonly colliderOwner: Map<number, Entity>;
```

***

### eventQueue

```ts
readonly eventQueue: any;
```

***

### rapier

```ts
readonly rapier: any;
```

***

### world

```ts
readonly world: any;
```

***

### is2D

```ts
readonly is2D: boolean;
```

## Methods

### bodyOf()

```ts
bodyOf(e): any;
```

The Rapier body for an entity, once created (the step after RigidBody was added).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `e` | `Entity` |

#### Returns

`any`

***

### applyImpulse()

```ts
applyImpulse(e, impulse): void;
```

Adds an instantaneous change in momentum (mass × velocity).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `e` | `Entity` |
| `impulse` | `Partial`<[`Vec3`](../../interfaces/Vec3.md)> |

#### Returns

`void`

***

### setVelocity()

```ts
setVelocity(e, v): void;
```

Sets linear velocity directly (same as writing LinearVelocity).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `e` | `Entity` |
| `v` | `Partial`<[`Vec3`](../../interfaces/Vec3.md)> |

#### Returns

`void`

***

### raycast()

```ts
raycast(
   origin, 
   dir, 
   maxDistance?, 
   exclude?
): RaycastHit | null;
```

Casts a ray and returns the first hit, or null. `exclude` skips one entity's colliders.

#### Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `origin` | [`Vec3`](../../interfaces/Vec3.md) | `undefined` |
| `dir` | [`Vec3`](../../interfaces/Vec3.md) | `undefined` |
| `maxDistance` | `number` | `1000` |
| `exclude?` | `Entity` | `undefined` |

#### Returns

[`RaycastHit`](../interfaces/RaycastHit.md) | `null`

***

### remove()

```ts
remove(e): void;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `e` | `Entity` |

#### Returns

`void`
