diff --git a/Assets/GameObjects/Prefabs/Player.prefab b/Assets/GameObjects/Prefabs/Player.prefab index b087049..7d25da7 100644 --- a/Assets/GameObjects/Prefabs/Player.prefab +++ b/Assets/GameObjects/Prefabs/Player.prefab @@ -655,6 +655,7 @@ MonoBehaviour: BulletHitLayer: serializedVersion: 2 m_Bits: 512 + Cooldown: 1 Lerpables: - {fileID: 2566772175078312154} - {fileID: 1798037817325599949} diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs index 666779e..0970cfe 100644 --- a/Assets/Scripts/Networking/Instances/Server.cs +++ b/Assets/Scripts/Networking/Instances/Server.cs @@ -12,7 +12,7 @@ namespace NeonTea.Quakeball.Networking.Instances { private NetChaperone Net; - private Dictionary Players = new Dictionary(); + public Dictionary Players { get; private set; } = new Dictionary(); public List PlayerList { get; private set; } = new List(); private ulong PlayerIdCounter; diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index c2d3295..c1a0c97 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -29,6 +29,7 @@ namespace NeonTea.Quakeball.Players { public Transform CameraRoot; public Transform BulletSourcePoint; public LayerMask BulletHitLayer; + public float Cooldown; [Header("Visuals")] public DesyncLerper[] Lerpables; @@ -87,6 +88,8 @@ namespace NeonTea.Quakeball.Players { private CharacterController CharacterController; private Vector3 FeetPosition; + private float LastShot; + /// Creates a PlayerUpdatePckt representing this Player's current status, for sending to other peers. public PlayerUpdatePckt CreateUpdatePacket(ulong id = 0) { return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Pitch, Yaw, id); @@ -154,6 +157,15 @@ namespace NeonTea.Quakeball.Players { } public void Shoot() { + float delta = Time.time - LastShot; + if (Net.Singleton.Instance is Server) { + float ping = ((Server)Net.Singleton.Instance).Players[NetId].Ping; + delta += ping; + } + if (delta < Cooldown) { + return; + } + LastShot = Time.time; Vector3 GunPoint = BulletSourcePoint.position; Vector3 ShotDelta = CameraRoot.forward * 1000f;