mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-18 13:58:28 +00:00
fix for wrong position of detached vehicle parts
This commit is contained in:
parent
eac9bce0c7
commit
38e23851c6
2 changed files with 43 additions and 6 deletions
|
@ -6,7 +6,23 @@ namespace SanAndreasUnity.Net
|
||||||
|
|
||||||
public class NetworkRigidBody : NetworkBehaviour
|
public class NetworkRigidBody : NetworkBehaviour
|
||||||
{
|
{
|
||||||
public Rigidbody Rigidbody { get; set; }
|
private Rigidbody _rigidbody;
|
||||||
|
public Rigidbody Rigidbody
|
||||||
|
{
|
||||||
|
get => _rigidbody;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_rigidbody == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_rigidbody = value;
|
||||||
|
|
||||||
|
if (NetStatus.IsClientOnly)
|
||||||
|
{
|
||||||
|
this.UpdateAllPropertiesOnClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SyncVar(hook=nameof(OnNetPositionChanged))] Vector3 m_net_position = Vector3.zero;
|
[SyncVar(hook=nameof(OnNetPositionChanged))] Vector3 m_net_position = Vector3.zero;
|
||||||
[SyncVar(hook=nameof(OnNetRotationChanged))] Vector3 m_net_rotation = Vector3.zero;
|
[SyncVar(hook=nameof(OnNetRotationChanged))] Vector3 m_net_rotation = Vector3.zero;
|
||||||
|
@ -35,6 +51,17 @@ namespace SanAndreasUnity.Net
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnStartClient()
|
||||||
|
{
|
||||||
|
if (NetStatus.IsServer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// need to apply initial syncvar values, because otherwise the object may stay on the place where it
|
||||||
|
// was originally spawned on the server (if object doesn't change position, syncvars will not be updated)
|
||||||
|
|
||||||
|
this.UpdateAllPropertiesOnClient();
|
||||||
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (NetStatus.IsServer)
|
if (NetStatus.IsServer)
|
||||||
|
@ -75,7 +102,7 @@ namespace SanAndreasUnity.Net
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateClient()
|
private void UpdateClient()
|
||||||
{
|
{
|
||||||
if (null == this.Rigidbody)
|
if (null == this.Rigidbody)
|
||||||
return;
|
return;
|
||||||
|
@ -92,6 +119,16 @@ namespace SanAndreasUnity.Net
|
||||||
this.Rigidbody.angularVelocity = m_net_angularVelocity;
|
this.Rigidbody.angularVelocity = m_net_angularVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateAllPropertiesOnClient()
|
||||||
|
{
|
||||||
|
if (null == this.Rigidbody)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.Rigidbody.MovePosition(m_net_position);
|
||||||
|
this.Rigidbody.MoveRotation(Quaternion.Euler(m_net_rotation));
|
||||||
|
this.UpdateClient();
|
||||||
|
}
|
||||||
|
|
||||||
void OnNetPositionChanged(Vector3 pos)
|
void OnNetPositionChanged(Vector3 pos)
|
||||||
{
|
{
|
||||||
if (NetStatus.IsServer)
|
if (NetStatus.IsServer)
|
||||||
|
|
|
@ -129,10 +129,10 @@ namespace SanAndreasUnity.Net
|
||||||
vehicle.DetachFrameDuringExplosion(m_net_frameName, m_net_mass, this.gameObject);
|
vehicle.DetachFrameDuringExplosion(m_net_frameName, m_net_mass, this.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.NetworkRigidBody.Rigidbody = this.GetComponentInChildren<Rigidbody>();
|
var rb = this.GetComponentInChildren<Rigidbody>();
|
||||||
if (this.NetworkRigidBody.Rigidbody != null)
|
if (rb != null)
|
||||||
this.NetworkRigidBody.Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
|
rb.interpolation = RigidbodyInterpolation.Interpolate;
|
||||||
this.NetworkRigidBody.UpdateClient();
|
this.NetworkRigidBody.Rigidbody = rb;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue