Beispiel #1
0
    public void OnTransformDataMessage(VNetMessageNetTransformData message)
    {
        // Get out the transform from the remote control stack
        if (!m_networkTransforms.ContainsKey(message.transformUID))
        {
            return;
        }
        VNetTransform trans = m_networkTransforms[message.transformUID];

        trans.AddRemoteDataPoint(message);
    }
Beispiel #2
0
    public override VNetMessage Clone()
    {
        VNetMessageNetTransformData clone = (VNetMessageNetTransformData)base.Clone();

        clone.transformUID  = transformUID;
        clone.time          = time;
        clone.localPosition = localPosition;
        clone.localRotation = localRotation;
        clone.rbVelocity    = rbVelocity;
        clone.rbRotation    = rbRotation;
        clone.rbSleeping    = rbSleeping;
        return(clone);
    }
Beispiel #3
0
    public void AddRemoteDataPoint(VNetMessageNetTransformData message)
    {
        TransformTrack temp = new TransformTrack();

        temp.angularVel = message.rbRotation;
        temp.vel        = message.rbVelocity;
        temp.pos        = message.localPosition;
        temp.rot        = message.localRotation;
        temp.isSleeping = message.rbSleeping;
        temp.netTime    = message.time;

        m_transformQueue.AddDataPoint(temp);
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        if (isRemoteControlled)
        {
            UpdateRemoteControl();
            return;
        }
        if (isLocalControlled)
        {
            // See where we expect the values to be...
            float   serverTime = VNetSessionTime.Inst.GetServerTime();
            float   t          = (serverTime - m_clientPrev.netTime) / (m_clientPost.netTime - m_clientPrev.netTime);
            Vector3 localPos   = Vector3.LerpUnclamped(m_clientPrev.pos, m_clientPost.pos, t);

            // compare this to current values
            float expectedOffSq = (localPos - transform.localPosition).sqrMagnitude;
            bool  updateRemote  = false;
            if (expectedOffSq > VNetManager.Inst.TransformPredictionSqDstOffset)
            {
                updateRemote = true;
            }

            if (!updateRemote)
            {
                Quaternion localRot = Quaternion.SlerpUnclamped(m_clientPrev.rot, m_clientPost.rot, t);
                Vector3    forw     = localRot * Vector3.forward;
                Vector3    comp     = transform.localRotation * Vector3.forward;

                if (Vector3.Dot(forw, comp) < VNetManager.Inst.TransformPredictionDotOffset)
                {
                    updateRemote = true;
                }
            }
            if (updateRemote)
            {
                lastSendTime = serverTime;

                // Create and send a message
                VNetMessageNetTransformData data = new VNetMessageNetTransformData();
                data.transformUID  = netIdentifier;
                data.time          = serverTime;
                data.localPosition = transform.localPosition;
                data.localRotation = transform.localRotation;

                if (rigidBody != null)
                {
                    data.rbSleeping = rigidBody.IsSleeping();
                    data.rbVelocity = rigidBody.velocity;
                    data.rbRotation = rigidBody.angularVelocity;
                }

                // This is now a reliable message
                VNet.Inst.SendToLobby(data, true);


                // Update the post and prev
                TransformTrack temp = m_clientPrev;
                m_clientPrev         = m_clientPost;
                m_clientPost         = temp;
                m_clientPost.netTime = lastSendTime;
                m_clientPost.pos     = transform.localPosition;
                m_clientPost.rot     = transform.localRotation;
                if (rigidBody != null)
                {
                    data.rbSleeping = rigidBody.IsSleeping();
                    data.rbVelocity = rigidBody.velocity;
                    data.rbRotation = rigidBody.angularVelocity;
                }
            }
        }
    }