2021年4月7日星期三

How to Copy Transform.rotation over Network (byte[]) in unity?

So I have this problem

I want to have indentical object rotation on client and on server. But somehow it won't work. client:

        byte[] buff = new byte[sizeof(float) * 3];          Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.x), 0, buff, 0 * sizeof(float), sizeof(float));          Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.y), 0, buff, 1 * sizeof(float), sizeof(float));          Buffer.BlockCopy(BitConverter.GetBytes(Object.eulerAngles.z), 0, buff, 2 * sizeof(float), sizeof(float));  

server:

    vect.x = BitConverter.ToSingle(msg.Array, msg.Array.Length - 3 * sizeof(float));      vect.y = BitConverter.ToSingle(msg.Array, msg.Array.Length - 2 * sizeof(float));      vect.z = BitConverter.ToSingle(msg.Array, msg.Array.Length - sizeof(float));        q = Quaternion.Euler(vect);      Debug.Log(q);      TargetObject_Transform.rotation = q;  
https://stackoverflow.com/questions/66977218/how-to-copy-transform-rotation-over-network-byte-in-unity April 07, 2021 at 06:22AM

没有评论:

发表评论