MultiConnectSDK › Physics
7. Physics on the server
Your server needs the same physics as your players. There are two ways to do this.
| Unity server | .NET server | |
|---|---|---|
| Set up in | The same scene and prefab, with Headless Mode on | Your own code, as in Script 7.1 |
| Physics components | All of them | Not available, because they need Unity |
| Best for | Most games, because there is only one setup to maintain | Servers that must start fast and use little memory |
On a .NET server, you build the world from code using the same engine underneath. To keep results identical, it must have the same sizes, masses, materials and order as the scene your players use. The Export to .NET Guide explains .NET servers in full.
Script 7.1: A physics world in plain code
using MultiConnect.Physics.Core;
using MultiConnect.Physics.FixedMath;
public class ServerWorld
{
public readonly MCPhysicsSpace Space;
public readonly MCRigidBody Ball;
public ServerWorld()
{
Space = new MCPhysicsSpace(new MCPhysicsSpaceSettings
{
FixedTimestep = Fix64.FromFraction(1, 60)
});
// Fixed scenery: a floor at height zero.
Space.AddStaticCollider(new MCBoxCollider(new MCVector3(Fix64.FromInt(50), Fix64.One, Fix64.FromInt(50))),
new MCVector3(Fix64.Zero, -Fix64.One, Fix64.Zero), MCQuaternion.Identity);
// A ball of half a metre radius, starting two metres up.
Ball = Space.CreateBody(new MCBodyDescriptor
{
Type = MCBodyType.Dynamic,
Collider = new MCSphereCollider(Fix64.Half),
Position = new MCVector3(Fix64.Zero, Fix64.FromInt(2), Fix64.Zero),
Rotation = MCQuaternion.Identity,
Mass = Fix64.One
});
}
// Call this 60 times a second.
public void Tick() => Space.StepFixed();
}

