# IPhysicsWorld interface

> A session's one physics world: its gravity, its bodies, and adding and removing them. It has no Godot in it, so the same calls work on a dedicated server.

Namespace `EvilEngine.Api.Physics`, assembly `EvilEngine.Api`. Engine commit 4ff877b1.

```csharp
public interface IPhysicsWorld
```

A session's one physics world: its gravity, its bodies, and adding and removing them. It has no Godot in it, so the same calls work on a dedicated server.

The host steps it, never a Plugin. Each tick, 0.015 s, it takes one step in the tick's Physics phase after the players move. The map's own colliders are already in it as static bodies, and they aren't in [Bodies](#bodies).

A Plugin reaches it through its context's [Physics](/docs/api/plugincontext#physics), which removes only what that Plugin added and takes it away when the Plugin unloads. The host's own `spawn` command, a death that leaves a ragdoll and `just map-shot --spawn` add bodies and joints to it too. A body added through the world is simulated and traced against but not drawn: spawn a prop for one players see.

```csharp
var drum = world.Add(new BodySpec(collision)
{
    Position = new MapVector(0, 2, 0),
    Orientation = Orientation.Yaw(45)
});
drum.Push(new MapVector(0, 0, -150), drum.Position);
```

## Members

### Gravity (property)

```csharp
MapVector Gravity { get; set; }
```

The world's gravity as a [MapVector](/docs/api/mapvector) in m/s². It starts as the map's own, straight down: 9.81 when the map doesn't say, and 15.24 on every Source map. Setting it changes it for every body at once.

### Bodies (property)

```csharp
IReadOnlyCollection<IPhysicsBody> Bodies { get; }
```

Every body [Add](#add) has made and [Remove](#remove) hasn't taken away, as [IPhysicsBody](/docs/api/iphysicsbody).

### Add (method)

```csharp
IPhysicsBody Add(BodySpec body)
```

Makes a body from a [BodySpec](/docs/api/bodyspec), puts it in the world and returns it. A dynamic body takes the spec's starting velocity and spin. A static or kinematic one ignores them.

Throws `ArgumentException` when the spec asks for a dynamic body over a collision holding a triangle mesh, since Jolt can't simulate one. Make it static or kinematic instead. Throws `ArgumentOutOfRangeException` for a number that isn't finite or is past a float's range, an orientation of all zeros, a mass or inertia of 0 or less, or damping below 0.

### Remove (method)

```csharp
bool Remove(IPhysicsBody body)
```

```csharp
bool Remove(IPhysicsJoint joint)
```

Takes a body out of the world and frees it. Returns `false` if the body isn't this world's or was already removed. Don't use a body after removing it. Removing a body also removes every joint on it.

Given an [IPhysicsJoint](/docs/api/iphysicsjoint), it takes the joint out of the world and frees it, leaving its bodies, and returns `false` if the joint isn't this world's or was already removed.

### Join (method)

```csharp
IPhysicsJoint Join(JointSpec joint)
```

Joins two of this world's bodies with a joint made from a [JointSpec](/docs/api/jointspec) and returns it. The joint holds the two pivots together and lets the child turn about the joint's three axes within its limits.

Throws `ArgumentException` when either body isn't this world's, was removed or is the other, or when the spec doesn't have three limits and three frictions. Throws `ArgumentOutOfRangeException` for a position, orientation or frame that isn't finite, a limit that isn't finite or has its least second, or friction below 0.
