mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
Sync rigid body's linear and angular velocity
This commit is contained in:
parent
9a01c2464a
commit
a7e0c91f31
3 changed files with 12 additions and 0 deletions
|
@ -14,6 +14,8 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
[SyncVar] float m_net_acceleration;
|
||||
[SyncVar] float m_net_steering;
|
||||
[SyncVar] float m_net_braking;
|
||||
[SyncVar] Vector3 m_net_linearVelocity;
|
||||
[SyncVar] Vector3 m_net_angularVelocity;
|
||||
|
||||
// is it better to place syncvars in Vehicle class ? - that way, there is no need for hooks
|
||||
// - or we could assign/read syncvars in Update()
|
||||
|
@ -79,12 +81,18 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
m_net_acceleration = m_vehicle.Accelerator;
|
||||
m_net_steering = m_vehicle.Steering;
|
||||
m_net_braking = m_vehicle.Braking;
|
||||
m_net_linearVelocity = m_vehicle.RigidBody.velocity;
|
||||
m_net_angularVelocity = m_vehicle.RigidBody.angularVelocity;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vehicle.Accelerator = m_net_acceleration;
|
||||
m_vehicle.Steering = m_net_steering;
|
||||
m_vehicle.Braking = m_net_braking;
|
||||
if (VehicleManager.Instance.syncLinearVelocity)
|
||||
m_vehicle.RigidBody.velocity = m_net_linearVelocity;
|
||||
if (VehicleManager.Instance.syncAngularVelocity)
|
||||
m_vehicle.RigidBody.angularVelocity = m_net_angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
|
||||
public GameObject vehiclePrefab;
|
||||
|
||||
public bool syncLinearVelocity = true;
|
||||
public bool syncAngularVelocity = true;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
public partial class Vehicle
|
||||
{
|
||||
private Rigidbody _rigidBody;
|
||||
public Rigidbody RigidBody => _rigidBody;
|
||||
|
||||
[Range(-1, 1)]
|
||||
public float Accelerator;
|
||||
|
|
Loading…
Reference in a new issue