Add shooty

This commit is contained in:
Jens Pitkänen 2020-08-08 05:26:17 +03:00
parent 48f02df34c
commit 7d60350142
7 changed files with 111 additions and 31 deletions

View File

@ -44,7 +44,6 @@ GameObject:
m_Component:
- component: {fileID: 1865991757674780053}
- component: {fileID: 2075495528035690810}
- component: {fileID: 6867077562160249920}
m_Layer: 0
m_Name: GunRoot
m_TagString: Untagged
@ -64,8 +63,8 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 8204020546429986303}
m_Father: {fileID: 7391558912382528812}
m_RootOrder: 2
m_Father: {fileID: 3811958100146932696}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!95 &2075495528035690810
Animator:
@ -86,19 +85,6 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &6867077562160249920
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2071588178488902664}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0e8b530a9e9275419a275e5557a0420, type: 3}
m_Name:
m_EditorClassIdentifier:
Speed: 10
--- !u!1 &2093411826205058927
GameObject:
m_ObjectHideFlags: 0
@ -194,6 +180,51 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &2970260390919355544
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3811958100146932696}
- component: {fileID: 4000144568201082722}
m_Layer: 0
m_Name: GunRootAboveAnimator
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3811958100146932696
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2970260390919355544}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1865991757674780053}
m_Father: {fileID: 7391558912382528812}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4000144568201082722
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2970260390919355544}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0e8b530a9e9275419a275e5557a0420, type: 3}
m_Name:
m_EditorClassIdentifier:
Speed: 10
--- !u!1 &7391558911651855222
GameObject:
m_ObjectHideFlags: 0
@ -445,7 +476,7 @@ Transform:
m_Children:
- {fileID: 7391558911651855223}
- {fileID: 7391558913556166742}
- {fileID: 1865991757674780053}
- {fileID: 3811958100146932696}
m_Father: {fileID: 7391558912167870012}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -576,7 +607,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
CoyoteTime: 0.2
CoyoteTimePingBias: 0
PingBias: 0
UpdateFrequency: 30
MoveStyles:
- {fileID: 11400000, guid: 550df8ac62d76a64a8c621ea6b32398f, type: 2}
@ -588,7 +619,7 @@ MonoBehaviour:
Lerpables:
- {fileID: 2566772175078312154}
- {fileID: 1798037817325599949}
- {fileID: 6867077562160249920}
- {fileID: 4000144568201082722}
Pitch: 0
Yaw: 0
BodyYaw: 0

View File

@ -142,6 +142,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
case PlayerAction.Jump:
Players[action.PlayerId].Controlled.Jump();
break;
case PlayerAction.Shoot:
ShootData shootData = (ShootData)action.Serializable;
HandleSyncPckt(shootData.SyncPckt);
Players[action.PlayerId].Controlled.Shoot();
break;
}
}
@ -161,10 +166,10 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
}
public override void LocalPlayerAction(PlayerAction action) {
public override void LocalPlayerAction(PlayerAction action, Serializable serializable = null) {
if (SelfIdentified && Server != null) {
PlayerActionPckt jump = new PlayerActionPckt(action);
Peer.SendReliable(Server.uid, jump);
PlayerActionPckt actionPckt = new PlayerActionPckt(action, serializable);
Peer.SendReliable(Server.uid, actionPckt);
}
}

View File

@ -25,7 +25,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
public abstract void UpdateLocalPlayer();
public abstract void SendPlayerSync();
public abstract void LocalPlayerAction(PlayerAction action);
public abstract void LocalPlayerAction(PlayerAction action, Serializable serializable = null);
public virtual void Update() { }

View File

@ -157,6 +157,17 @@ namespace NeonTea.Quakeball.Networking.Instances {
SendReliableToAll(action);
}
break;
case PlayerAction.Shoot:
ShootData shootData = (ShootData)action.Serializable;
HandleSyncPckt(uid, shootData.SyncPckt);
Players[uid].Controlled.Shoot();
action.PlayerId = uid;
NetPlayer Player = Players[uid];
shootData.SyncPckt = Player.Controlled.CreateSyncPacket(Player.Id, Player.Unsynced);
Player.Unsynced = false;
SendReliableToAll(action);
break;
}
}
@ -183,9 +194,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
SendUnreliableToAll(pckt);
}
public override void LocalPlayerAction(PlayerAction action) {
PlayerActionPckt jump = new PlayerActionPckt(action, LocalPlayer.Id);
SendReliableToAll(jump);
public override void LocalPlayerAction(PlayerAction action, Serializable serializable = null) {
PlayerActionPckt actionPckt = new PlayerActionPckt(action, serializable, LocalPlayer.Id);
SendReliableToAll(actionPckt);
}
public override void SendPlayerSync() {

View File

@ -1,4 +1,4 @@
using UnityEngine;
using NeonTea.Quakeball.TeaNet.Packets;
namespace NeonTea.Quakeball.Networking.Packets {
@ -9,8 +9,9 @@ namespace NeonTea.Quakeball.Networking.Packets {
public Serializable Serializable;
public PlayerActionPckt() { }
public PlayerActionPckt(PlayerAction action, ulong id = 0) {
public PlayerActionPckt(PlayerAction action, Serializable serializable, ulong id = 0) {
Action = action;
Serializable = serializable;
PlayerId = id;
}
@ -22,9 +23,8 @@ namespace NeonTea.Quakeball.Networking.Packets {
break;
case 1:
Action = PlayerAction.Shoot;
ShootData data = new ShootData();
data.Read(buffer);
Serializable = data;
Serializable = new ShootData();
Serializable.Read(buffer);
break;
}
}
@ -45,10 +45,28 @@ namespace NeonTea.Quakeball.Networking.Packets {
}
public class ShootData : Serializable {
public float Pitch;
public float Yaw;
public PlayerSyncPacket SyncPckt;
public ShootData() { }
public ShootData(float pitch, float yaw, PlayerSyncPacket syncPckt) {
Pitch = pitch;
Yaw = yaw;
SyncPckt = syncPckt;
}
public void Read(ByteBuffer buffer) {
Pitch = buffer.ReadFloat();
Yaw = buffer.ReadFloat();
SyncPckt = new PlayerSyncPacket();
SyncPckt.Read(buffer);
}
public void Write(ByteBuffer buffer) {
buffer.Write(Pitch);
buffer.Write(Yaw);
SyncPckt.Write(buffer);
}
}
}

View File

@ -19,6 +19,7 @@ namespace NeonTea.Quakeball.Players {
private InputAction MoveAction;
private InputAction CrouchAction;
private InputAction JumpAction;
private InputAction ShootAction;
private float PreviousPlayerUpdate = -1;
private float PreviousPlayerFullSync = -1;
@ -46,6 +47,13 @@ namespace NeonTea.Quakeball.Players {
.With("Left", "<Keyboard>/a")
.With("Right", "<Keyboard>/d");
ShootAction = new InputAction("Shoot", binding: "<Mouse>/leftButton");
ShootAction.performed += _ => {
ShootData shootData = new ShootData(Player.Pitch, Player.Yaw, Player.CreateSyncPacket());
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData);
Player.Shoot();
};
Terminal.Singleton.RegisterCommand("tp", args => {
if (args.Length != 3) {
return false;
@ -61,6 +69,7 @@ namespace NeonTea.Quakeball.Players {
JumpAction.Disable();
LookAction.Disable();
MoveAction.Disable();
ShootAction.Disable();
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
} else {
@ -68,6 +77,7 @@ namespace NeonTea.Quakeball.Players {
JumpAction.Enable();
LookAction.Enable();
MoveAction.Enable();
ShootAction.Enable();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}

View File

@ -1,6 +1,7 @@
using UnityEngine;
using NeonTea.Quakeball.Networking.Packets;
using NeonTea.Quakeball.Util;
using NeonTea.Quakeball.Interface;
namespace NeonTea.Quakeball.Players {
/// <summary>The central glue class for players (both local and remote).</summary>
@ -133,6 +134,10 @@ namespace NeonTea.Quakeball.Players {
}
}
public void Shoot() {
Terminal.Singleton.Println("<color=#F00><b>BANG!</b></color>");
}
public bool IsGrounded() {
return CharacterController.isGrounded && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0;
}