sync rotation too

This commit is contained in:
mischa 2023-09-06 11:00:38 +02:00
parent da1c247a73
commit 29bb6ef399

View File

@ -40,6 +40,7 @@ protected override void OnValidate()
public override void OnSerialize(NetworkWriter writer, bool initialState)
{
writer.WriteVector3(rb.position);
writer.WriteQuaternion(rb.rotation);
writer.WriteVector3(rb.velocity);
}
@ -47,13 +48,15 @@ public override void OnSerialize(NetworkWriter writer, bool initialState)
// this is where reconciliation happens if necessary.
public override void OnDeserialize(NetworkReader reader, bool initialState)
{
double timestamp = NetworkClient.connection.remoteTimeStamp;
Vector3 position = reader.ReadVector3();
Vector3 velocity = reader.ReadVector3();
double timestamp = NetworkClient.connection.remoteTimeStamp;
Vector3 position = reader.ReadVector3();
Quaternion rotation = reader.ReadQuaternion();
Vector3 velocity = reader.ReadVector3();
// hard force for now.
// TODO compare past position at timestamp, and only correct if needed
rb.position = position;
rb.rotation = rotation;
rb.velocity = velocity;
}
}