public
Created

Syncs Droid movement over the network using dead reckoning

  • Download Gist
DroidController.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
if (stream.isWriting) {
var position = transform.position;
var rotation = transform.rotation;
 
stream.Serialize(ref movementSpeed);
stream.Serialize(ref currentHorizontalMovement);
stream.Serialize(ref currentVerticalMovement);
stream.Serialize(ref position);
stream.Serialize(ref rotation);
}
else {
Vector3 position = Vector3.zero;
Quaternion rotation = Quaternion.identity;
 
stream.Serialize(ref movementSpeed);
stream.Serialize(ref currentHorizontalMovement);
stream.Serialize(ref currentVerticalMovement);
stream.Serialize(ref position);
stream.Serialize(ref rotation);
 
transform.position = position;
transform.rotation = rotation;
 
useNetworkInput = true;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.