Skip to content

Collisions

Dominik Winkelbauer edited this page Jun 26, 2017 · 4 revisions

Collision & Trigger

As we need to manually synchronize transformations of rigidbodies, we also need to synchronize collision and trigger events.

Adjust your project

So instead of using the default Unity events like OnCollisionEnter, OnTriggerStay you have to use the corresponding synchronized methods. To get this work your script also needs to inherit from our CollisionSynchronization class instead of the Unity's MonoBehaviour.

UnityEngine CAVE
OnCollisionEnter(Collision collision) OnSynchronizedCollisionEnter(GameObject other)
OnCollisionExit(Collision collision) OnSynchronizedCollisionExit(GameObject other)
OnCollisionStay(Collision collision) OnSynchronizedCollisionStay(GameObject other)
OnTriggerEnter(Collider other) OnSynchronizedTriggerEnter(GameObject other)
OnTriggerExit(Collider other) OnSynchronizedTriggerExit(GameObject other)
OnTriggerStay(Collider other) OnSynchronizedTriggerStay(GameObject other)

Important:

Synchronized collision and trigger events are only processed for game objects which own an initialized NetworkIdentity component!

What does not work?

  • Synchronized events only offer the other game object as a parameter (Unity also delivers a little bit more information like collision time and point)
  • Unity can pack multiple collisions which happen in the same cycle into one Collision object. As we do not support this, such events are split up into multiple synchronized collision events.

How it works

Collisions are synchronized by the general EventSynchronizer.

Package

InputEventsMessage
int eventsLength
Event[] events

Subpackages

Event
uint networkId
uint data
short type

(type = OnCollisionEnter, OnCollisionExit, OnCollisionStay, OnTriggerEnter, OnTriggerExit, OnTriggerStay or OnClick)

Clone this wiki locally