mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 12:58:27 +00:00
fix for initial vehicle position being at (0,0,0)
This commit is contained in:
parent
847d5186da
commit
961a7e601f
1 changed files with 18 additions and 8 deletions
|
@ -85,7 +85,7 @@ namespace SanAndreasUnity.Net
|
||||||
|
|
||||||
// apply initial sync data
|
// apply initial sync data
|
||||||
// first sync should've been done before calling this function, so the data is available
|
// first sync should've been done before calling this function, so the data is available
|
||||||
this.ApplyCurrentSyncData();
|
this.WarpToLatestSyncData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnSerialize(NetworkWriter writer, bool initialState)
|
public bool OnSerialize(NetworkWriter writer, bool initialState)
|
||||||
|
@ -215,17 +215,27 @@ namespace SanAndreasUnity.Net
|
||||||
m_currentSyncData.Position = this.GetPosition();
|
m_currentSyncData.Position = this.GetPosition();
|
||||||
m_currentSyncData.Rotation = this.GetRotation();
|
m_currentSyncData.Rotation = this.GetRotation();
|
||||||
}
|
}
|
||||||
m_currentSyncData.CalculatedVelocityMagnitude = 0;
|
m_currentSyncData.CalculatedVelocityMagnitude = float.PositiveInfinity;
|
||||||
m_currentSyncData.CalculatedAngularVelocityMagnitude = 0;
|
m_currentSyncData.CalculatedAngularVelocityMagnitude = float.PositiveInfinity;
|
||||||
|
m_nextSyncData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyCurrentSyncData()
|
public void WarpToLatestSyncData()
|
||||||
{
|
{
|
||||||
if (!m_hasTransform)
|
var syncData = m_nextSyncData ?? m_currentSyncData;
|
||||||
return;
|
|
||||||
|
|
||||||
this.SetPosition();
|
this.SetPosition(syncData.Position);
|
||||||
this.SetRotation();
|
this.SetRotation(syncData.Rotation);
|
||||||
|
|
||||||
|
// also assign position/rotation directly to transform, because rigid body may not warp
|
||||||
|
if (m_hasTransform)
|
||||||
|
{
|
||||||
|
m_transform.localPosition = syncData.Position;
|
||||||
|
m_transform.localRotation = syncData.Rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_currentSyncData = syncData;
|
||||||
|
m_nextSyncData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPosition()
|
private void SetPosition()
|
||||||
|
|
Loading…
Add table
Reference in a new issue