Ejemplo n.º 1
0
    void SendHeading()
    {
        Heading current = new Heading();

        Vector3 currPos = transform.position;
        float currAngle = Convert.ToSingle(2*Math.Atan2(transform.rotation.y, transform.rotation.w));
        ThirdPersonController playerController = GetComponent<ThirdPersonController>();
        float currSpeed = playerController.GetSpeed();
        long currTime = ServerClock.Instance.GetTime();

        if (playerController.IsAccelerating())
        {
            float currEndSpeed = playerController.GetEndSpeed();
            long currAccelerationTime = playerController.GetAccelerationTime();
            current.InitFromValues(currPos, currAngle, currTime, currSpeed, currEndSpeed, currAccelerationTime);
        }
        else
        {
            current.InitFromValues(currPos, currAngle, currTime, currSpeed);
        }

        bool headingChanged = !current.IsFutureOf(lastState);

        if(headingChanged)
        {
            //Debug.Log("last: "+lastState);
            //Debug.Log("curr: "+current);
            lastState = current;
            lastState.Send();
        }
    }