【问题标题】:How to Copy Transform.rotation over Network (byte[]) in unity?如何在网络上统一复制 Transform.rotation(字节 [])?
【发布时间】:2021-07-02 17:50:20
【问题描述】:

所以我有这个问题

我想在客户端和服务器上进行相同的对象轮换。但不知何故,它不会工作。 客户:

        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));

服务器:

    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;

【问题讨论】:

  • 似乎是一个错字。不应该是msgArray.Length - 1 - (1,2, or 3) * sizeof(float) 吗?为什么不像(0, 1, or 2) * sizeof(float) 那样在BlockCopy 调用中表达它?
  • rot.x = BitConverter.ToSingle(msg, offset * sizeof(float) + 0 * sizeof(float)); // 这就是我开始工作时的格式

标签: c# unity3d networking quaternions


【解决方案1】:

所以我想通了..

我没有考虑到我的客户端消息大小是 1024 字节,以及我从数组中取出 mytes 的事实。长度 - 减去位置实际上与我想要的字节的实际位置相去甚远.一旦我从正确的地方得到字节。一切正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2014-08-09
    • 2012-11-30
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多