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 }
public bool AddMoveIfNew(Move inMove) { //we might have already received this move in another packet ( since we're sending the same move in multiple packets ) //so make sure it's new... //adjust the deltatime and then place! float timeStamp = inMove.GetTimestamp(); if (timeStamp > mLastMoveTimestamp) { float deltaTime = mLastMoveTimestamp >= 0.0f ? timeStamp - mLastMoveTimestamp : 0.0f; mLastMoveTimestamp = timeStamp; mMoves.Add(new Move(inMove.GetInputState(), timeStamp, deltaTime)); return(true); } return(false); }