Exemple #1
0
        public override void Tick(Structs.Input input)
        {
            Vector3 force = new Vector3();

            if (input.Forward)
            {
                force += Vector3.forward * Force;
            }
            if (input.Backward)
            {
                force += Vector3.back * Force;
            }
            if (input.Left)
            {
                force += Vector3.left * Force;
            }
            if (input.Right)
            {
                force += Vector3.right * Force;
            }

            rb.AddForce(force);
        }
 public abstract void Tick(Structs.Input input);
Exemple #3
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (!connected)
            {
                return;
            }
            netManager.PollEvents();

            if (!ticking)
            {
                return;
            }
            Tick += 1;

            /*var position = player.position;
             * var packet = new ClientSendPositionPacket
             * {
             *  x = position.x,
             *  y = position.y,
             *  z = position.z,
             *  tick = Tick
             * };
             * SendPacket(packet, DeliveryMethod.Unreliable);*/

            var input = new Structs.Input
            {
                Forward  = UnityEngine.Input.GetKey(KeyCode.W),
                Left     = UnityEngine.Input.GetKey(KeyCode.A),
                Backward = UnityEngine.Input.GetKey(KeyCode.S),
                Right    = UnityEngine.Input.GetKey(KeyCode.D)
            };

            inputs.Add(Tick, input);

            TickManager.RunTick(input);
            Physics.Simulate(0.02f);

            if (Tick - maxTicks > earliestTick)
            {
                deleteTicks(earliestTick, Tick - maxTicks);
            }

            Debug.Log("inputs.Count: " + inputs.Count);

            earliestTick = Tick - maxTicks;

            {
                int repeats = Tick - lastTickReceived;

                var inputPacket = new ClientInputPacket
                {
                    inputs   = new Structs.Input[repeats],
                    lastTick = Tick
                };

                for (int i = 0; i < repeats; i++)
                {
                    if (inputs.ContainsKey(lastTickReceived + i))
                    {
                        inputPacket.inputs[i] = inputs[lastTickReceived + i];
                    }
                    else
                    {
                        continue;
                    }
                }

                SendPacket(inputPacket, DeliveryMethod.Sequenced);

                Debug.Log("Input Packet Sent");
            }

            Debug.Log("lastTickReceived = " + lastTickReceived);
        }