diff --git a/Assets/Prefabs/LocalPlayer.prefab b/Assets/Prefabs/LocalPlayer.prefab index 880c49c..35108ca 100644 --- a/Assets/Prefabs/LocalPlayer.prefab +++ b/Assets/Prefabs/LocalPlayer.prefab @@ -237,7 +237,6 @@ MonoBehaviour: m_EditorClassIdentifier: Camera: {fileID: 9173392441446035453} DisableInput: 0 - TestingPlayer: {fileID: 0} --- !u!114 &3508289943927587728 MonoBehaviour: m_ObjectHideFlags: 0 @@ -291,34 +290,6 @@ PrefabInstance: propertyPath: m_TagString value: Player objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} propertyPath: m_RootOrder value: 0 diff --git a/Assets/Prefabs/NetChaperone.prefab b/Assets/Prefabs/NetChaperone.prefab index 521526f..20c7d8b 100644 --- a/Assets/Prefabs/NetChaperone.prefab +++ b/Assets/Prefabs/NetChaperone.prefab @@ -43,4 +43,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 74110215548fa9145b867baf649d14b0, type: 3} m_Name: m_EditorClassIdentifier: - SpawnedRemotePlayer: {fileID: 6246660765983498204, guid: 0fd59d93bc0809e4c8bca733a842cb6f, type: 3} + SpawnedRemotePlayer: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3} diff --git a/Assets/Prefabs/RemotePlayer.prefab b/Assets/Prefabs/RemotePlayer.prefab deleted file mode 100644 index 531229e..0000000 --- a/Assets/Prefabs/RemotePlayer.prefab +++ /dev/null @@ -1,80 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &2280554230953742630 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6246660765983498204} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f10708676bd58ed419f4c9ab7caeec69, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!1001 &3469055348080435163 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_Name - value: RemotePlayer - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_TagString - value: RemotePlayer - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 0bffd92c46c257840806f5e957954800, type: 3} ---- !u!1 &6246660765983498204 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3} - m_PrefabInstance: {fileID: 3469055348080435163} - m_PrefabAsset: {fileID: 0} diff --git a/Assets/Prefabs/RemotePlayer.prefab.meta b/Assets/Prefabs/RemotePlayer.prefab.meta deleted file mode 100644 index f2f1d34..0000000 --- a/Assets/Prefabs/RemotePlayer.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 0fd59d93bc0809e4c8bca733a842cb6f -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Networking/Instances/Client.cs b/Assets/Scripts/Networking/Instances/Client.cs index d7440d3..27a8fbb 100644 --- a/Assets/Scripts/Networking/Instances/Client.cs +++ b/Assets/Scripts/Networking/Instances/Client.cs @@ -78,7 +78,7 @@ namespace NeonTea.Quakeball.Networking.Instances { } } else if (packet is PlayerJumpPckt) { PlayerJumpPckt jump = (PlayerJumpPckt)packet; - // Jump! + Players[jump.PlayerId].Controlled.Jump(); } } @@ -86,7 +86,7 @@ namespace NeonTea.Quakeball.Networking.Instances { if (pckt.PlayerId == LocalPlayer.Id) { return; // Ignore, again. } - Players[pckt.PlayerId].Controlled.GetComponent().ProcessPacket(pckt); + Players[pckt.PlayerId].Controlled.ProcessPacket(ref pckt); } public override void UpdateLocalPlayer() { diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs index 8a69d7a..1d385a0 100644 --- a/Assets/Scripts/Networking/Instances/Server.cs +++ b/Assets/Scripts/Networking/Instances/Server.cs @@ -78,14 +78,15 @@ namespace NeonTea.Quakeball.Networking.Instances { PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet; if (Players[conn.uid].Controlled != null) { updatePckt.PlayerId = conn.uid; - Players[conn.uid].Controlled.GetComponent().ProcessPacket(updatePckt); + Players[conn.uid].Controlled.ProcessPacket(ref updatePckt); } } else if (packet is PlayerJumpPckt) { PlayerJumpPckt jump = (PlayerJumpPckt)packet; if (Players[conn.uid].Controlled != null) { - // Check if Players[conn.uid].Controlled can jump, and do the following if true - jump.PlayerId = conn.uid; - SendReliableToAll(jump); + if (Players[conn.uid].Controlled.Jump()) { + jump.PlayerId = conn.uid; + SendReliableToAll(jump); + } } } } diff --git a/Assets/Scripts/Players/LocalPlayer.cs b/Assets/Scripts/Players/LocalPlayer.cs index cf11211..5f0867a 100644 --- a/Assets/Scripts/Players/LocalPlayer.cs +++ b/Assets/Scripts/Players/LocalPlayer.cs @@ -10,8 +10,6 @@ namespace NeonTea.Quakeball.Players { public Transform Camera; public bool DisableInput = false; - public RemotePlayer TestingPlayer; - private float Lean = 0; private Player Player; @@ -73,18 +71,21 @@ namespace NeonTea.Quakeball.Players { Camera.localEulerAngles = new Vector3(Player.Pitch, Player.Yaw, Lean); if (Time.time - PreviousPlayerUpdate >= 1f / Player.UpdateFrequency) { + PreviousPlayerUpdate = Time.time; + Vector2 MovementInput = MoveAction.ReadValue(); Vector3 Move = new Vector3(MovementInput.x, 0, MovementInput.y); Move = Quaternion.Euler(0, Player.Yaw, 0) * Move; Player.MoveDirection = Move; Player.CurrentMoveStyle = CrouchAction.ReadValue() > 0 ? (byte)1 : (byte)0; - Player.Jumping = WantsToJump; - PreviousPlayerUpdate = Time.time; - WantsToJump = false; - if (Networking.Net.Singleton.Instance != null) { Networking.Net.Singleton.Instance.UpdateLocalPlayer(); } + + if (WantsToJump && Player.Jump()) { + Networking.Net.Singleton.Instance.LocalPlayerJump(); + } + WantsToJump = false; } } } diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index 4e485cd..63ffcbd 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -31,9 +31,6 @@ namespace NeonTea.Quakeball.Players { /// The direction the player is going. public Vector3 MoveDirection; - /// The player's desire to jump currently. - public bool Jumping; - /// The amount of movement the player wants to happen. /// Without analog controls, always 0 or 1. public float InputSpeed; @@ -90,6 +87,15 @@ namespace NeonTea.Quakeball.Players { } } + public bool Jump() { + if (IsGrounded()) { + GravitationalVelocity = Vector3.up * MoveStyle.JumpVelocity; + return true; + } else { + return false; + } + } + public bool IsGrounded() { return Time.time - GroundedTime <= CoyoteTime && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0; } @@ -111,14 +117,10 @@ namespace NeonTea.Quakeball.Players { private void UpdateMovement() { bool Grounded = IsGrounded(); - if (Grounded) { - if (Vector3.Dot(Vector3.down, GravitationalVelocity) > 0) { - GravitationalVelocity = Vector3.zero; - } - if (Jumping) { - GravitationalVelocity = Vector3.up * MoveStyle.JumpVelocity; - } - } else { + bool FallingDown = Vector3.Dot(Vector3.down, GravitationalVelocity) > 0; + if (Grounded && FallingDown) { + GravitationalVelocity = Vector3.zero; + } else if (!Grounded) { GravitationalVelocity += Physics.gravity * Time.deltaTime; } diff --git a/Assets/Scripts/Players/RemotePlayer.cs b/Assets/Scripts/Players/RemotePlayer.cs deleted file mode 100644 index 7cf0d23..0000000 --- a/Assets/Scripts/Players/RemotePlayer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using UnityEngine; -using NeonTea.Quakeball.Networking.Packets; -using NeonTea.Quakeball.Interface; - -namespace NeonTea.Quakeball.Players { - /// A controller class for a remote player. Gets updates from the network and touches the relevant components. - [RequireComponent(typeof(Player))] - public class RemotePlayer : MonoBehaviour { - private Player Player; - - public void ProcessPacket(PlayerUpdatePckt packet) { - Player.ProcessPacket(ref packet); - } - - private void Awake() { - Player = GetComponent(); - } - } -} diff --git a/Assets/Scripts/Players/RemotePlayer.cs.meta b/Assets/Scripts/Players/RemotePlayer.cs.meta deleted file mode 100644 index 269f1cc..0000000 --- a/Assets/Scripts/Players/RemotePlayer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f10708676bd58ed419f4c9ab7caeec69 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 50 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: