sync movement input and heading

This commit is contained in:
in0finite 2019-07-07 23:41:18 +02:00
parent b1acdecd20
commit 6da98dd68a
2 changed files with 26 additions and 1 deletions

View file

@ -31,6 +31,9 @@ namespace SanAndreasUnity.Behaviours
public static int NumStateChangesReceived { get; private set; }
[SyncVar] Vector3 m_net_movementInput;
[SyncVar] Vector3 m_net_heading;
//[SyncVar(hook=nameof(Net_OnWeaponChanged))] GameObject m_net_weaponGameObject;
[SyncVar(hook=nameof(Net_OnWeaponChanged))] int m_net_currentWeaponSlot;
@ -84,9 +87,10 @@ namespace SanAndreasUnity.Behaviours
void Update_Net()
{
// update syncvars
if (NetStatus.IsServer)
{
// update syncvars
if (this.PedDef != null && this.PedDef.Id != m_net_pedId)
m_net_pedId = this.PedDef.Id;
@ -107,11 +111,28 @@ namespace SanAndreasUnity.Behaviours
m_net_state = newStateName;
}
if (m_net_movementInput != this.Movement)
m_net_movementInput = this.Movement;
if (m_net_heading != this.Heading)
m_net_heading = this.Heading;
if (this.WeaponHolder.CurrentWeaponSlot != m_net_currentWeaponSlot)
{
m_net_currentWeaponSlot = this.WeaponHolder.CurrentWeaponSlot;
}
}
else
{
// apply syncvars
if (!this.IsControlledByLocalPlayer)
{
this.Movement = m_net_movementInput;
this.Heading = m_net_heading;
}
}
// send input to server

View file

@ -21,6 +21,10 @@
- send aim/fire input to server
- sync fire event
- gun flash doesn't work on client ?
- weapon sound should be 3d