Example #1
0
    public override void Update()
    {
        if (GetPlayerId() == NetworkManagerClient.sInstance.GetPlayerId())
        {
            core.Move pendingMove = InputManager.sInstance.GetAndClearPendingMove();
            //in theory, only do this if we want to sample input this frame / if there's a new move ( since we have to keep in sync with server )
            if (pendingMove != null) //is it time to sample a new move...
            {
                float deltaTime = pendingMove.GetDeltaTime();

                //apply that input

                ProcessInput(deltaTime, pendingMove.GetInputState());

                //and simulate!

                SimulateMovement(deltaTime);

                //Debug.Log( "Local Client Move Time: " + pendingMove.GetTimestamp()  +" deltaTime: "+ deltaTime + " left rot at " + GetRotation() + " location: " + GetLocation() );
            }
        }
        else
        {
            SimulateMovement(core.Timing.sInstance.GetDeltaTime());

            if (GetVelocity().IsZero())
            {
                //we're in sync if our velocity is 0
                mTimeLocationBecameOutOfSync = 0.0f;
            }

            //Debug.Log("Remote Client Location : " + GetLocation() + ", player_id : " + GetPlayerId());
        }

#if _USE_BEPU_PHYSICS
        mCharacterController.Body.Position = GetLocation().CopyTo(ref physicsLocation);
        mDirection.CopyTo(ref mCharacterController.HorizontalMotionConstraint.LastDirection);
        if (mCharacterController.HorizontalMotionConstraint.MovementMode != BEPUphysics.Character.MovementMode.Floating)
        {
            if (GetVelocity().IsZero() == false)
            {
                mCharacterController.Body.LinearVelocity = GetVelocity().CopyTo(ref physicsVelocity);
            }
        }
#endif
    }