This commit is contained in:
Sofia 2017-05-11 22:20:39 +03:00
commit 74cda9ff18
2 changed files with 14 additions and 10 deletions

View File

@ -33,6 +33,8 @@ namespace Cyber.Entities.SyncBases {
private Vector3 MovementDirection = new Vector3(); private Vector3 MovementDirection = new Vector3();
private Vector3 ServerPosition = new Vector3(); private Vector3 ServerPosition = new Vector3();
private bool ServerPositionShouldLerpSync = false; private bool ServerPositionShouldLerpSync = false;
private Vector3 ServerRotation = new Vector3();
private bool ServerRotationShouldLerpSync = false;
/// <summary> /// <summary>
/// Moves the character in the given direction. /// Moves the character in the given direction.
@ -124,7 +126,7 @@ namespace Cyber.Entities.SyncBases {
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
ServerPosition = reader.ReadVector3(); ServerPosition = reader.ReadVector3();
Vector3 ServerMovementDirection = reader.ReadVector3(); Vector3 ServerMovementDirection = reader.ReadVector3();
Vector3 ServerRotation = reader.ReadVector3(); ServerRotation = reader.ReadVector3();
float Drift = (ServerPosition - GetPosition()).magnitude; float Drift = (ServerPosition - GetPosition()).magnitude;
@ -135,12 +137,10 @@ namespace Cyber.Entities.SyncBases {
MovementDirection = ServerMovementDirection; MovementDirection = ServerMovementDirection;
} }
// Update position more often (with lerping) if this is not the local player // Update position and rotation more often (with lerping)
if (Drift < 0.1) { // if this is not the local player
ServerPositionShouldLerpSync = false; ServerRotationShouldLerpSync = !LocalCharacter.Equals(this);
} else if (!LocalCharacter.Equals(this)) { ServerPositionShouldLerpSync = !LocalCharacter.Equals(this) && Drift > 0.1;
ServerPositionShouldLerpSync = true;
}
} }
/// <summary> /// <summary>
@ -157,6 +157,13 @@ namespace Cyber.Entities.SyncBases {
if (ServerPositionShouldLerpSync) { if (ServerPositionShouldLerpSync) {
SetPosition(Vector3.Lerp(GetPosition(), ServerPosition, 10f * Time.deltaTime)); SetPosition(Vector3.Lerp(GetPosition(), ServerPosition, 10f * Time.deltaTime));
} }
if (ServerRotationShouldLerpSync) {
Quaternion ServerRot = Quaternion.Euler(ServerRotation);
Quaternion LocalRot = Quaternion.Euler(GetRotation());
Vector3 NewRot = Quaternion.Lerp(LocalRot, ServerRot,
10f * Time.deltaTime).eulerAngles;
SetRotation(NewRot);
}
} }
private void FixedUpdate() { private void FixedUpdate() {

View File

@ -66,9 +66,6 @@ namespace Cyber.Util {
string Hash = CreateHash(text); string Hash = CreateHash(text);
if (forceRender || !Cache.ContainsKey(Hash)) { if (forceRender || !Cache.ContainsKey(Hash)) {
Cache[Hash] = Singleton.RenderText(text); Cache[Hash] = Singleton.RenderText(text);
Term.Println("Created a new texture for:");
Term.Println(Hash);
Term.Println("====");
} }
return Cache[Hash]; return Cache[Hash];
} }