Fix some of the movement jitter problems

This commit is contained in:
excitedneon 2017-05-09 18:20:10 +03:00
parent fcd3aef1c9
commit fc1e8085bc
2 changed files with 21 additions and 5 deletions

View File

@ -25,6 +25,8 @@ namespace Cyber.Entities {
public Transform Head;
private Vector3 MovementDirection = new Vector3();
private Vector3 ServerPosition = new Vector3();
private bool SyncToServerPosition = false;
/// <summary>
/// Moves the character in the given direction.
@ -90,8 +92,13 @@ namespace Cyber.Entities {
/// </summary>
/// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) {
transform.position = reader.ReadVector3();
Move(reader.ReadVector3());
ServerPosition = reader.ReadVector3();
float Drift = (ServerPosition - transform.position).magnitude;
if (Drift > 1) {
SyncToServerPosition = true;
} else if (Drift < 0.01) {
SyncToServerPosition = false;
}
Vector3 rot = reader.ReadVector3();
}
@ -101,10 +108,19 @@ namespace Cyber.Entities {
/// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) {
writer.Write(transform.position);
writer.Write(MovementDirection);
writer.Write(GetRotation());
}
private void Update() {
if (SyncToServerPosition) {
// LERP version
//transform.position = Vector3.Lerp(transform.position, ServerPosition, 50f * Time.deltaTime);
// Non-LERP version
transform.position = ServerPosition;
SyncToServerPosition = false;
}
}
private void FixedUpdate() {
CharacterController.Move(MovementDirection * MovementSpeed * Time.fixedDeltaTime);
}

View File

@ -23,9 +23,9 @@ UnityConnectSettings:
m_TestConfigUrl:
UnityAdsSettings:
m_Enabled: 0
m_InitializeOnStartup: 1
m_InitializeOnStartup: 0
m_TestMode: 0
m_EnabledPlatforms: 4294967295
m_EnabledPlatforms: 4294964991
m_IosGameId:
m_AndroidGameId:
PerformanceReportingSettings: