Skip to content

Physics

Dominik Winkelbauer edited this page Jun 7, 2017 · 2 revisions

Physics

As Unity's physic engine is not deterministic, we have to sync the resulting transformation of rigid body objects in every frame.

Adjust your project

Add NetworkIdentity components

Add a NetworkIdentity component to every game object whose transformation should be synchronized (The game object must also have a rigid body component!). This will synchronize the local position, rotation an scale of the object across all nodes (only if one of them changed).

Be careful: Do not sync too many objects (>300) as their transformations are synced every frame they change.

Dynamically created objects

If you want to sync the transformation of dynamically created objects, you have spawn them using the NetworkServer.Spawn() method on master. Of course the used prefab must also have a NetworkIdentity component.

What does not work?

  • every code you might want to run in a FixedUpdate() method: FixedUpdate is called by Unity's physic engine which is not synced!

How it works

At the beginning of every Update() call the master sends the transformation of all objects which have changed in the last Unity physics computation to all slaves.

Package

InputTransformationMessage
int transformLength
Transform[] transforms

Subpackages

Transform
uint networkId
Vector3 localPosition
Vector3 localEulerAngles
Vector3 localScale
Vector3
float x
float y
float z

Clone this wiki locally