mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add approaches using Lerp and SLerp
This commit is contained in:
parent
a83f3ad2ad
commit
8fe78bd956
1 changed files with 54 additions and 2 deletions
|
@ -9,6 +9,17 @@ namespace SanAndreasUnity.Net
|
|||
{
|
||||
public bool useSmoothDeltaTime = false;
|
||||
|
||||
public float lerpFactor = 0.8f;
|
||||
|
||||
public enum ClientUpdateType
|
||||
{
|
||||
Constant,
|
||||
Lerp,
|
||||
Slerp,
|
||||
}
|
||||
|
||||
public ClientUpdateType clientUpdateType = ClientUpdateType.Constant;
|
||||
|
||||
private SyncInfo m_syncInfo;
|
||||
private SyncData m_syncData;
|
||||
|
||||
|
@ -101,11 +112,24 @@ namespace SanAndreasUnity.Net
|
|||
}
|
||||
else
|
||||
{
|
||||
this.UpdateBasedOnSyncData();
|
||||
switch (this.clientUpdateType)
|
||||
{
|
||||
case ClientUpdateType.Constant:
|
||||
this.UpdateClientUsingVelocity();
|
||||
break;
|
||||
case ClientUpdateType.Lerp:
|
||||
this.UpdateClientUsingLerp();
|
||||
break;
|
||||
case ClientUpdateType.Slerp:
|
||||
this.UpdateClientUsingSphericalLerp();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBasedOnSyncData()
|
||||
private void UpdateClientUsingVelocity()
|
||||
{
|
||||
SyncInfo syncInfo = m_syncInfo;
|
||||
|
||||
|
@ -139,6 +163,34 @@ namespace SanAndreasUnity.Net
|
|||
m_syncInfo = syncInfo;
|
||||
}
|
||||
|
||||
private void UpdateClientUsingLerp()
|
||||
{
|
||||
m_syncInfo.Transform.localPosition = Vector3.Lerp(
|
||||
m_syncInfo.Transform.localPosition,
|
||||
m_syncInfo.Position,
|
||||
1 - Mathf.Exp(-this.lerpFactor * this.GetDeltaTime()));
|
||||
|
||||
m_syncInfo.Transform.localRotation = Quaternion.Lerp(
|
||||
m_syncInfo.Transform.localRotation,
|
||||
m_syncInfo.Rotation,
|
||||
1 - Mathf.Exp(-this.lerpFactor * this.GetDeltaTime()));
|
||||
|
||||
}
|
||||
|
||||
private void UpdateClientUsingSphericalLerp()
|
||||
{
|
||||
m_syncInfo.Transform.localPosition = Vector3.Slerp(
|
||||
m_syncInfo.Transform.localPosition,
|
||||
m_syncInfo.Position,
|
||||
1 - Mathf.Exp(-this.lerpFactor * this.GetDeltaTime()));
|
||||
|
||||
m_syncInfo.Transform.localRotation = Quaternion.Slerp(
|
||||
m_syncInfo.Transform.localRotation,
|
||||
m_syncInfo.Rotation,
|
||||
1 - Mathf.Exp(-this.lerpFactor * this.GetDeltaTime()));
|
||||
|
||||
}
|
||||
|
||||
private float GetDeltaTime()
|
||||
{
|
||||
return this.useSmoothDeltaTime ? Time.smoothDeltaTime : Time.deltaTime;
|
||||
|
|
Loading…
Reference in a new issue