Hi Everyone,
I have just completed this tutorial series:
Now i think i have a slight understanding of networking… what i am struggling to do is send rotation information over the network.
If I wanted to send the rotation details or if i wanted to send the entire Transform information of an object how would i do this?
Also can you send constant force details?
I am trying to make an Authoritative Server that accepts the position, rotation and constant force details of an object.
If someone can kindly advise i would be obliged.
Thanks,
J.
Send the quaternion of the transform you want rotated over the network.
Is this what i want to do ?
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
Vector3 pos = transform.position;
stream.Serialize(ref pos);
Quaternion rot = Quaternion.identity;
stream.Serialize(ref rot);
float CF = transform.constantForce.relativeForce.y;
}
else
{
Vector3 posReceive = Vector3.zero;
stream.Serialize(ref posReceive);
transform.position = posReceive;
Quaternion rotReceive = Quaternion.Euler(new Vector3(0, 0, 0));
stream.Serialize(ref rotReceive);
transform.rotation = rotReceive;
float CFReceive = transform.constantForce.relativeForce.y;
stream.Serialize(ref CFReceive);
transform.constantForce.relativeForce = new Vector3(0, CFReceive, 0);
Debug.LogWarning("CF " + CFReceive);
}
}
Close, what you did was send a Quaternion that has nothing to do with the transform, what you want to do is this:
Quaternion rot = transform.rotation;
stream.Serialize(ref rot);
Thanks Khopcraft this worked a treat !!!
I also just fixed another problem where it was only updating on the server side.
I realised that the Network View of the player object was set to “Off” I have changed this to “Unreliable” and the client and the server states are maintained.
Thank you for your help !