Remove RemotePlayer prefab and script (use Player instead), implement jumping pckt

This commit is contained in:
Jens Pitkänen 2020-08-07 23:25:56 +03:00
parent 45954dab1a
commit a0b286cbd6
10 changed files with 28 additions and 170 deletions

View File

@ -237,7 +237,6 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Camera: {fileID: 9173392441446035453} Camera: {fileID: 9173392441446035453}
DisableInput: 0 DisableInput: 0
TestingPlayer: {fileID: 0}
--- !u!114 &3508289943927587728 --- !u!114 &3508289943927587728
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -291,34 +290,6 @@ PrefabInstance:
propertyPath: m_TagString propertyPath: m_TagString
value: Player value: Player
objectReference: {fileID: 0} 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} - target: {fileID: 7391558912774766616, guid: 0bffd92c46c257840806f5e957954800, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 0

View File

@ -43,4 +43,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 74110215548fa9145b867baf649d14b0, type: 3} m_Script: {fileID: 11500000, guid: 74110215548fa9145b867baf649d14b0, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
SpawnedRemotePlayer: {fileID: 6246660765983498204, guid: 0fd59d93bc0809e4c8bca733a842cb6f, type: 3} SpawnedRemotePlayer: {fileID: 7391558912774766599, guid: 0bffd92c46c257840806f5e957954800, type: 3}

View File

@ -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}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 0fd59d93bc0809e4c8bca733a842cb6f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -78,7 +78,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
} }
} else if (packet is PlayerJumpPckt) { } else if (packet is PlayerJumpPckt) {
PlayerJumpPckt jump = (PlayerJumpPckt)packet; PlayerJumpPckt jump = (PlayerJumpPckt)packet;
// Jump! Players[jump.PlayerId].Controlled.Jump();
} }
} }
@ -86,7 +86,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
if (pckt.PlayerId == LocalPlayer.Id) { if (pckt.PlayerId == LocalPlayer.Id) {
return; // Ignore, again. return; // Ignore, again.
} }
Players[pckt.PlayerId].Controlled.GetComponent<RemotePlayer>().ProcessPacket(pckt); Players[pckt.PlayerId].Controlled.ProcessPacket(ref pckt);
} }
public override void UpdateLocalPlayer() { public override void UpdateLocalPlayer() {

View File

@ -78,14 +78,15 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet; PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
if (Players[conn.uid].Controlled != null) { if (Players[conn.uid].Controlled != null) {
updatePckt.PlayerId = conn.uid; updatePckt.PlayerId = conn.uid;
Players[conn.uid].Controlled.GetComponent<RemotePlayer>().ProcessPacket(updatePckt); Players[conn.uid].Controlled.ProcessPacket(ref updatePckt);
} }
} else if (packet is PlayerJumpPckt) { } else if (packet is PlayerJumpPckt) {
PlayerJumpPckt jump = (PlayerJumpPckt)packet; PlayerJumpPckt jump = (PlayerJumpPckt)packet;
if (Players[conn.uid].Controlled != null) { if (Players[conn.uid].Controlled != null) {
// Check if Players[conn.uid].Controlled can jump, and do the following if true if (Players[conn.uid].Controlled.Jump()) {
jump.PlayerId = conn.uid; jump.PlayerId = conn.uid;
SendReliableToAll(jump); SendReliableToAll(jump);
}
} }
} }
} }

View File

@ -10,8 +10,6 @@ namespace NeonTea.Quakeball.Players {
public Transform Camera; public Transform Camera;
public bool DisableInput = false; public bool DisableInput = false;
public RemotePlayer TestingPlayer;
private float Lean = 0; private float Lean = 0;
private Player Player; private Player Player;
@ -73,18 +71,21 @@ namespace NeonTea.Quakeball.Players {
Camera.localEulerAngles = new Vector3(Player.Pitch, Player.Yaw, Lean); Camera.localEulerAngles = new Vector3(Player.Pitch, Player.Yaw, Lean);
if (Time.time - PreviousPlayerUpdate >= 1f / Player.UpdateFrequency) { if (Time.time - PreviousPlayerUpdate >= 1f / Player.UpdateFrequency) {
PreviousPlayerUpdate = Time.time;
Vector2 MovementInput = MoveAction.ReadValue<Vector2>(); Vector2 MovementInput = MoveAction.ReadValue<Vector2>();
Vector3 Move = new Vector3(MovementInput.x, 0, MovementInput.y); Vector3 Move = new Vector3(MovementInput.x, 0, MovementInput.y);
Move = Quaternion.Euler(0, Player.Yaw, 0) * Move; Move = Quaternion.Euler(0, Player.Yaw, 0) * Move;
Player.MoveDirection = Move; Player.MoveDirection = Move;
Player.CurrentMoveStyle = CrouchAction.ReadValue<float>() > 0 ? (byte)1 : (byte)0; Player.CurrentMoveStyle = CrouchAction.ReadValue<float>() > 0 ? (byte)1 : (byte)0;
Player.Jumping = WantsToJump;
PreviousPlayerUpdate = Time.time;
WantsToJump = false;
if (Networking.Net.Singleton.Instance != null) { if (Networking.Net.Singleton.Instance != null) {
Networking.Net.Singleton.Instance.UpdateLocalPlayer(); Networking.Net.Singleton.Instance.UpdateLocalPlayer();
} }
if (WantsToJump && Player.Jump()) {
Networking.Net.Singleton.Instance.LocalPlayerJump();
}
WantsToJump = false;
} }
} }
} }

View File

@ -31,9 +31,6 @@ namespace NeonTea.Quakeball.Players {
/// <summary>The direction the player is going.</summary> /// <summary>The direction the player is going.</summary>
public Vector3 MoveDirection; public Vector3 MoveDirection;
/// <summary>The player's desire to jump currently.</summary>
public bool Jumping;
/// <summary>The amount of movement the player wants to happen.</summary> /// <summary>The amount of movement the player wants to happen.</summary>
/// <remarks>Without analog controls, always 0 or 1.</remarks> /// <remarks>Without analog controls, always 0 or 1.</remarks>
public float InputSpeed; 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() { public bool IsGrounded() {
return Time.time - GroundedTime <= CoyoteTime && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0; return Time.time - GroundedTime <= CoyoteTime && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0;
} }
@ -111,14 +117,10 @@ namespace NeonTea.Quakeball.Players {
private void UpdateMovement() { private void UpdateMovement() {
bool Grounded = IsGrounded(); bool Grounded = IsGrounded();
if (Grounded) { bool FallingDown = Vector3.Dot(Vector3.down, GravitationalVelocity) > 0;
if (Vector3.Dot(Vector3.down, GravitationalVelocity) > 0) { if (Grounded && FallingDown) {
GravitationalVelocity = Vector3.zero; GravitationalVelocity = Vector3.zero;
} } else if (!Grounded) {
if (Jumping) {
GravitationalVelocity = Vector3.up * MoveStyle.JumpVelocity;
}
} else {
GravitationalVelocity += Physics.gravity * Time.deltaTime; GravitationalVelocity += Physics.gravity * Time.deltaTime;
} }

View File

@ -1,19 +0,0 @@
using UnityEngine;
using NeonTea.Quakeball.Networking.Packets;
using NeonTea.Quakeball.Interface;
namespace NeonTea.Quakeball.Players {
/// <summary>A controller class for a remote player. Gets updates from the network and touches the relevant components.</summary>
[RequireComponent(typeof(Player))]
public class RemotePlayer : MonoBehaviour {
private Player Player;
public void ProcessPacket(PlayerUpdatePckt packet) {
Player.ProcessPacket(ref packet);
}
private void Awake() {
Player = GetComponent<Player>();
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f10708676bd58ed419f4c9ab7caeec69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 50
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: