Beispiel #1
0
 public void MySyncVar(HandlePacket.Packet pkt)
 {
     HandlePacket.coord kk = pkt.State.state_base.pos;
     if (!isServer)
     {
         if (pkt.State.state_base.name.ToString() != hp.myname.ToString())
         {
             if (isYanni)
             {
                 heidi.transform.position = new Vector3(Convert.ToSingle(kk.x), Convert.ToSingle(kk.y), Convert.ToSingle(kk.z));
             }
             if (isHeidi)
             {
                 yanni.transform.position = new Vector3(Convert.ToSingle(kk.x), Convert.ToSingle(kk.y), Convert.ToSingle(kk.z));
             }
         }
     }
     else
     {
         //DisplayPacket(pkt.C, pkt.State);
         if (pkt.State.state_base.name.ToString() == hp.myname.ToString())
         {
             yanni.transform.position = new Vector3(Convert.ToSingle(kk.x), Convert.ToSingle(kk.y), Convert.ToSingle(kk.z));
         }
     }
 }
Beispiel #2
0
        public byte[] ClientWritePacket(GameObject go, UInt32 count)
        {
            byte[]   spare0 = new byte[2];
            UInt32[] spare1 = new UInt32[4];

            Vector3 pos_c = Geometry.transform.position;
            Vector3 pos_a = Geometry.transform.eulerAngles;

            HandlePacket.coord pos   = new HandlePacket.coord(pos_c.z, -pos_c.x, pos_c.y, Convert.ToSingle(-pos_a.y * Math.PI / 180f), Convert.ToSingle(pos_a.x * Math.PI / 180f), Convert.ToSingle(pos_a.z * Math.PI / 180f), 0x01 | 0x02, 0, 0); // change it here
            HandlePacket.coord speed = GetMySpeed(go);
            HandlePacket.coord accel = new HandlePacket.coord(0, 0, 0, 0, 0, 0, 0x01, 0, 0);
            HandlePacket.geo   geo   = new HandlePacket.geo(4.6f, 1.86f, 1.6f, 0.8f, 0, 0.3f);

            HandlePacket.wheel_o[] wheel_O = new HandlePacket.wheel_o[4];
            float rotAngle = GetMyRotAngle();

            wheel_O[0] = new HandlePacket.wheel_o(1, 0, 0, spare0, 1, -0.025f, rotAngle / 180 * Mathf.PI, 0, -carController.CurrentSteerAngle / 180 * Mathf.PI, spare1);
            wheel_O[1] = new HandlePacket.wheel_o(1, 1, 0, spare0, 1, -0.025f, rotAngle / 180 * Mathf.PI, 0, -carController.CurrentSteerAngle / 180 * Mathf.PI, spare1);
            wheel_O[2] = new HandlePacket.wheel_o(1, 2, 0, spare0, 1, -0.025f, rotAngle / 180 * Mathf.PI, 0, 0, spare1);
            wheel_O[3] = new HandlePacket.wheel_o(1, 3, 0, spare0, 1, -0.025f, rotAngle / 180 * Mathf.PI, 0, 0, spare1);

            simTime = stopwatch1.Elapsed.TotalSeconds;
            buffer  = HandlePacket.Catch.CatchPacket(simTime, m_Id, geo, pos, speed, accel, count, wheel_O);
            return(buffer);
        }
Beispiel #3
0
        // related to communication packets

        public HandlePacket.coord GetMySpeed(GameObject gameObject)
        {
            Vector3   speed_c   = new Vector3();
            Vector3   speed_a   = new Vector3();
            Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>();

            speed_c = rigidbody.velocity * 2.23693629f;
            speed_a = rigidbody.angularVelocity;                                                                                                      // This is in radians per second
            HandlePacket.coord speed = new HandlePacket.coord(speed_c.z, -speed_c.x, speed_c.y, -speed_a.y, speed_a.x, speed_a.z, 0x01 | 0x02, 0, 0); // change it here
            return(speed);
        }
Beispiel #4
0
        public byte[] ClientWritePacket(GameObject go, UInt32 count)
        {
            Vector3 pos   = go.transform.position;
            Vector3 speed = new Vector3(0, 0, 0);
            Vector3 accel = new Vector3(0, 0, 0);
            Vector3 geo   = new Vector3(0, 0, 0);

            HandlePacket.coord mypos   = HandlePacket.Catch.CatchCoord(pos);
            HandlePacket.coord myspeed = HandlePacket.Catch.CatchCoord(speed);
            HandlePacket.coord myaccel = HandlePacket.Catch.CatchCoord(accel);
            HandlePacket.geo   mygeo   = HandlePacket.Catch.CatchGeo(geo);
            buffer = HandlePacket.Catch.CatchPacket(mygeo, mypos, myspeed, myaccel, count);
            return(buffer);
        }
Beispiel #5
0
        public Vector3 ParseCoord(HandlePacket.Packet pkt, int flag1, bool flag2)
        {
            // flag1 is the option for "pos"(1) and "speed"(2), flag2 stands for "angular"(0) and "coordinates"(1)
            HandlePacket.coord pos = pkt.State.state_base.pos;
            HandlePacket.coord speed = pkt.State.state_ext.speed;
            Vector3            pos_c, pos_a, speed_c, speed_a = new Vector3();

            pos_c   = new Vector3(-Convert.ToSingle(pos.y), Convert.ToSingle(pos.z), Convert.ToSingle(pos.x));
            pos_a   = new Vector3(Convert.ToSingle(pos.p * 180f / Mathf.PI), Convert.ToSingle(-pos.h * 180f / Mathf.PI), Convert.ToSingle(pos.r * 180f / Mathf.PI));
            speed_c = new Vector3(-Convert.ToSingle(speed.y), Convert.ToSingle(speed.z), Convert.ToSingle(speed.x));
            speed_a = new Vector3(Convert.ToSingle(speed.p), Convert.ToSingle(-speed.h), Convert.ToSingle(speed.r));
            if (flag1 == 1)
            {
                if (flag2)
                {
                    return(pos_c);
                }
                else
                {
                    return(pos_a);
                }
            }
            else if (flag1 == 2)
            {
                if (flag2)
                {
                    return(speed_c);
                }
                else
                {
                    return(speed_a);
                }
            }
            else
            {
                Debug.Log("No such a flag");
                return(new Vector3(0, 0, 0));
            }
        }