void SimulateMovment() { if (!bNetworkSmoothingComplete) { SmoothClientPosition_Interpolate(ENetworkSmoothingMode.Linear); SmoothClientPosition_UpdateVisuals(ENetworkSmoothingMode.Linear); } else { if (ServerLastMove.timestamp != 0 || CurrentStartPhotonTime != ServerLastMove.timestamp) { CurrentStartPhotonTime = ServerLastMove.timestamp; CurrentStartPhotonTime -= Time.deltaTime; // for now additional latency InterpolationFrameStartTime = CurrentStartPhotonTime; float distance = Vector3.Distance(transform.position, ServerLastMove.getPostion()); if (distance > 0.01) // we start interpolating { bNetworkSmoothingComplete = false; orginaloffsetPostion = transform.position; // targetoffsetPostion = ServerLastMove.getPostion(); orginaloffsetRotation = transform.rotation; targetoffsetRotation = Quaternion.Euler(ServerLastMove.getRotationAngle()); interpoationTargetTime = ServerLastMove.timestamp; } } } if (ServerLastMove.shooting) { Shooting(); } if (ServerLastMove.stand) { Stand(); } }
private void PerformeMovment(SavedMove savedMove, float deltaTime) { if (savedMove.stand) { BotState = BotState.Standing; animat.SetInteger("condition", 0); } else { BotState = BotState.Moving; animat.SetInteger("condition", 1); } Vector3 MoveDirection = savedMove.getDirection(); Move(MoveDirection, deltaTime); transform.rotation = Quaternion.Euler(savedMove.getRotationAngle()); if (savedMove.shooting) { Shooting(); } }
private void SmoothClientPosition_Interpolate(SavedMove ClientData, SavedMove ClientDataNext, ENetworkSmoothingMode smoothingMode) { //if (ClientDataNext.shooting) //{ // Shooting(); //} //if (ClientDataNext.stand) //{ // BotState = BotState.Standing; // animat.SetInteger("condition", 0); // double RemainingTime = ClientDataNext.timestamp - ClientData.timestamp; // double LastCorrectionDelta = ClientDataNext.timestamp - InterpolationFrameStartTime; // double LerpPercent = RemainingTime / LastCorrectionDelta; // transform.position = Vector3.Lerp(ClientData.getPostion(), ClientDataNext.getPostion(), (float)LerpPercent); // //is this good ? // // Debug.Log(botColor + " interpolating to" + ClientDataNext.timestamp + " desired postion " + ClientDataNext.getPostion() + " shooting " + ClientDataNext.shooting + " standing " + ClientDataNext.stand); // interpolating = false; //} //else if (smoothingMode == ENetworkSmoothingMode.Linear) { // Debug.Log(botColor + " interpolating to" + ClientDataNext.timestamp + " desired postion " + ClientDataNext.getPostion() + " shooting " + ClientDataNext.shooting + " standing " + ClientDataNext.stand); float LerpPercent = 0f; const float LerpLimit = 1.15f; CurrentStartPhotonTime += Time.deltaTime; // if time is right ReplicatedMovement double RemainingTime = ClientDataNext.timestamp - ClientData.timestamp; double LastCorrectionDelta = ClientDataNext.timestamp - InterpolationFrameStartTime; double CurrentSmoothTime = LastCorrectionDelta - RemainingTime; // Debug.Log("TIMES server " + ServerData.timestamp + " client data " + ClientData.timestamp + " CurrentStartPhotonTime " + CurrentStartPhotonTime + " started this shiet on " + InterpolationFrameStartTime); double toClamp = CurrentSmoothTime / LastCorrectionDelta; LerpPercent = Mathf.Clamp((float)toClamp, 0.0f, LerpLimit); // Debug.Log("TIMES serverpack " + ServerData.timestamp + " client data " + ClientData.timestamp + " LastCorrectionDelta "+ LastCorrectionDelta+ " RemainingTime " + RemainingTime + " Percent " + LerpPercent); if (LerpPercent >= 1.0f - 0.001f) { interpolating = false; CurrentStartPhotonTime = ClientDataNext.timestamp; transform.rotation = Quaternion.Euler(ClientDataNext.getRotationAngle()); } else { BotState = BotState.Moving; if (!ClientDataNext.shooting) { animat.SetInteger("condition", 1); } Vector3 offset = Vector3.Lerp(Vector3.zero, orginaloffsetPostion, LerpPercent); Vector3 CurrentDelta = ClientData.getPostion() - ClientDataNext.getPostion(); Vector3 finalPostion = transform.position + offset; //Debug.Log(" orginaloffset " + orginaloffsetPostion + "percent " + LerpPercent + " offset " + offset + " postion from " + ClientData.getPostion() + " to " + ClientDataNext.getPostion() + " delta beetween " + CurrentDelta + " postion after adding offset" + finalPostion); Quaternion rotationOffset = Quaternion.Lerp(orginaloffsetRotation, Quaternion.Euler(ClientDataNext.getRotationAngle()), LerpPercent); transform.rotation = rotationOffset; //transform.position = finalPostion; Move(offset, Time.deltaTime); } } else if (smoothingMode == ENetworkSmoothingMode.Exponential) { } else if (smoothingMode == ENetworkSmoothingMode.Replay) { float StartTime = Time.time; if (CurrentReplayTime >= ClientData.timestamp && CurrentReplayTime <= ClientDataNext.timestamp) { const float EPSILON = 0.01f; double Delta = ClientDataNext.timestamp - ClientData.timestamp; float LerpPercent; if (Delta > EPSILON) { double toClamp = (CurrentReplayTime - ClientData.timestamp) / Delta; LerpPercent = Mathf.Clamp((float)toClamp, 0.0f, 1.0f); } else { LerpPercent = 1.0f; } Vector3 Location = Vector3.Lerp(ClientData.getPostion(), ClientDataNext.getPostion(), LerpPercent); Quaternion rotation = Quaternion.Lerp(Quaternion.Euler(ClientData.getRotationAngle()), Quaternion.Euler(ClientDataNext.getRotationAngle()), LerpPercent); //normailzed ? //Debug.Log("REPLAY Time on " + botColor + CurrentReplayTime + " location from " + ClientData.getPostion() + "loc to" + ClientDataNext.getPostion() + " lerp " + Location + " my postion " + transform.position + " rotation " + rotation); transform.position = Location; transform.rotation = rotation; //PerformeMovment(ClientData, Time.deltaTime); } else { Debug.Log("REPLAY TIME NOT CAUGHT Q!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } float DeltaTime = Time.time - StartTime; CurrentReplayTime += DeltaTime; } else { } }