From 0127b0d3925822965f7a59070723d45884501e90 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sat, 13 Jul 2019 01:20:12 +0200 Subject: [PATCH] send fire position to server --- Assets/Scripts/Behaviours/Ped/Ped.cs | 1 + Assets/Scripts/Behaviours/Ped/Ped_Networking.cs | 2 ++ .../Behaviours/Ped/States/BaseAimMovementState.cs | 2 +- Assets/Scripts/Networking/PedSync.cs | 9 +++++---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index aaa34790..9c2e9bdc 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -91,6 +91,7 @@ namespace SanAndreasUnity.Behaviours public Weapon CurrentWeapon { get { return m_weaponHolder.CurrentWeapon; } } public bool IsFiring { get { return m_weaponHolder.IsFiring; } } public Vector3 AimDirection { get { return m_weaponHolder.AimDirection; } set => m_weaponHolder.AimDirection = value; } + public Vector3 FirePosition => this.CurrentWeapon != null ? this.CurrentWeapon.GetFirePos() : this.transform.position; public Vector3 FireDirection => this.CurrentWeapon != null ? this.CurrentWeapon.GetFireDir() : this.AimDirection; public bool IsAimOn { get ; set ; } public bool IsFireOn { get ; set ; } diff --git a/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs b/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs index ccb4c182..bd6b1333 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped_Networking.cs @@ -41,6 +41,8 @@ namespace SanAndreasUnity.Behaviours [SyncVar(hook=nameof(Net_OnWeaponChanged))] int m_net_currentWeaponSlot; [SyncVar] internal Vector3 m_net_aimDir; + + public Vector3 NetFirePos { get; set; } public Vector3 NetFireDir { get; set; } diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs index ca17d5b8..01389ebb 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs @@ -421,7 +421,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States if (m_ped.IsControlledByLocalPlayer || null == m_ped.PlayerOwner) return this.TryFire(m_weapon.GetFirePos(), m_weapon.GetFireDir()); else // this ped is owned by remote client - return this.TryFire(m_weapon.GetFirePos(), m_ped.NetFireDir); + return this.TryFire(m_ped.NetFirePos, m_ped.NetFireDir); } } return false; diff --git a/Assets/Scripts/Networking/PedSync.cs b/Assets/Scripts/Networking/PedSync.cs index 26bcffbd..d57b2741 100644 --- a/Assets/Scripts/Networking/PedSync.cs +++ b/Assets/Scripts/Networking/PedSync.cs @@ -33,21 +33,21 @@ namespace SanAndreasUnity.Net } public void SendInput(bool isWalkOn, bool isRunOn, bool isSprintOn, Vector3 movementInput, - bool isJumpOn, Vector3 heading, Vector3 aimDir, Vector3 fireDir, bool isAimOn, bool isFireOn) + bool isJumpOn, Vector3 heading, Vector3 aimDir, Vector3 firePos, Vector3 fireDir, bool isAimOn, bool isFireOn) { - this.CmdSendingInput(isWalkOn, isRunOn, isSprintOn, movementInput, isJumpOn, heading, aimDir, fireDir, isAimOn, isFireOn); + this.CmdSendingInput(isWalkOn, isRunOn, isSprintOn, movementInput, isJumpOn, heading, aimDir, firePos, fireDir, isAimOn, isFireOn); } public void SendInput() { Ped ped = m_ped; this.SendInput(ped.IsWalkOn, ped.IsRunOn, ped.IsSprintOn, ped.Movement, ped.IsJumpOn, ped.Heading, - ped.AimDirection, ped.FireDirection, ped.IsAimOn, ped.IsFireOn); + ped.AimDirection, ped.FirePosition, ped.FireDirection, ped.IsAimOn, ped.IsFireOn); } [Command] void CmdSendingInput(bool isWalkOn, bool isRunOn, bool isSprintOn, Vector3 movementInput, - bool isJumpOn, Vector3 heading, Vector3 aimDir, Vector3 fireDir, bool isAimOn, bool isFireOn) + bool isJumpOn, Vector3 heading, Vector3 aimDir, Vector3 firePos, Vector3 fireDir, bool isAimOn, bool isFireOn) { if (null == m_ped) return; @@ -61,6 +61,7 @@ namespace SanAndreasUnity.Net ped.IsJumpOn = isJumpOn; ped.Heading = heading; ped.AimDirection = aimDir; + ped.NetFirePos = firePos; ped.NetFireDir = fireDir; ped.IsAimOn = isAimOn; ped.IsFireOn = isFireOn;