Remove stopwatch and add player lerping after desync

This commit is contained in:
Jens Pitkänen 2020-08-08 04:17:54 +03:00
parent 1317c59e94
commit d5edcab211
7 changed files with 84 additions and 362 deletions

View File

@ -44,6 +44,7 @@ GameObject:
m_Component:
- component: {fileID: 1865991757674780053}
- component: {fileID: 2075495528035690810}
- component: {fileID: 6867077562160249920}
m_Layer: 0
m_Name: GunRoot
m_TagString: Untagged
@ -85,6 +86,19 @@ 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
@ -191,6 +205,7 @@ GameObject:
- component: {fileID: 7391558911651855223}
- component: {fileID: 7391558911651855114}
- component: {fileID: 7391558911651855113}
- component: {fileID: 1798037817325599949}
m_Layer: 0
m_Name: HeadMesh
m_TagString: Untagged
@ -262,6 +277,19 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &1798037817325599949
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7391558911651855222}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0e8b530a9e9275419a275e5557a0420, type: 3}
m_Name:
m_EditorClassIdentifier:
Speed: 10
--- !u!1 &7391558911947395338
GameObject:
m_ObjectHideFlags: 0
@ -548,6 +576,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
CoyoteTime: 0.2
CoyoteTimePingBias: 0
UpdateFrequency: 30
MoveStyles:
- {fileID: 11400000, guid: 550df8ac62d76a64a8c621ea6b32398f, type: 2}
@ -556,16 +585,20 @@ MonoBehaviour:
Body: {fileID: 7391558913662534769}
Gun: {fileID: 1865991757674780053}
GunBobber: {fileID: 2075495528035690810}
Lerpables:
- {fileID: 2566772175078312154}
- {fileID: 1798037817325599949}
- {fileID: 6867077562160249920}
Pitch: 0
Yaw: 0
BodyYaw: 0
MoveDirection: {x: 0, y: 0, z: 0}
Jumping: 0
InputSpeed: 0
CurrentMoveStyle: 0
GroundVelocity: {x: 0, y: 0, z: 0}
GravitationalVelocity: {x: 0, y: 0, z: 0}
GroundedTime: 0
LatestGroundedY: 0
GroundCastLength: 0.2
GroundLayer:
serializedVersion: 2
@ -627,6 +660,7 @@ GameObject:
- component: {fileID: 7391558913662534769}
- component: {fileID: 7391558913662534772}
- component: {fileID: 7391558913662534771}
- component: {fileID: 2566772175078312154}
m_Layer: 0
m_Name: BodyMesh
m_TagString: Untagged
@ -697,6 +731,19 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &2566772175078312154
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7391558913662534768}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0e8b530a9e9275419a275e5557a0420, type: 3}
m_Name:
m_EditorClassIdentifier:
Speed: 10
--- !u!1 &7583110057160188895
GameObject:
m_ObjectHideFlags: 0

View File

@ -867,140 +867,6 @@ Transform:
m_Father: {fileID: 524351210}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &37339646
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 37339647}
- component: {fileID: 37339649}
- component: {fileID: 37339648}
m_Layer: 5
m_Name: Header
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &37339647
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 37339646}
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: []
m_Father: {fileID: 459987321}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 10, y: -10}
m_SizeDelta: {x: -20, y: 40}
m_Pivot: {x: 0, y: 1}
--- !u!114 &37339648
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 37339646}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Stopwatch (press T):'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 35.75
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 1
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &37339649
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 37339646}
m_CullTransparentMesh: 0
--- !u!1 &45244044
GameObject:
m_ObjectHideFlags: 0
@ -5062,57 +4928,6 @@ Light:
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &459987320
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 459987321}
- component: {fileID: 459987322}
m_Layer: 5
m_Name: Stopwatch
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &459987321
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 459987320}
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: 37339647}
- {fileID: 1687974938}
m_Father: {fileID: 1734890299}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 219.8, y: -99}
m_SizeDelta: {x: 349.81427, y: 113.80438}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &459987322
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 459987320}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 61e1b888bc9173449923055928c4d73d, type: 3}
m_Name:
m_EditorClassIdentifier:
TimingText: {fileID: 1687974939}
--- !u!1 &524351209
GameObject:
m_ObjectHideFlags: 0
@ -17006,140 +16821,6 @@ Light:
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1687974937
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1687974938}
- component: {fileID: 1687974940}
- component: {fileID: 1687974939}
m_Layer: 5
m_Name: Timing
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1687974938
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1687974937}
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: []
m_Father: {fileID: 459987321}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -10, y: 10}
m_SizeDelta: {x: -20, y: 50}
m_Pivot: {x: 1, y: 0}
--- !u!114 &1687974939
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1687974937}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 0.00 s
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 44.75
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 4
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 1
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1687974940
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1687974937}
m_CullTransparentMesh: 0
--- !u!43 &1734066939
Mesh:
m_ObjectHideFlags: 0
@ -17394,7 +17075,6 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 459987321}
- {fileID: 267525579}
m_Father: {fileID: 187747573}
m_RootOrder: 0

View File

@ -1,38 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;
namespace NeonTea.Quakeball.Interface {
public class Stopwatch : MonoBehaviour {
public TMP_Text TimingText;
private InputAction ToggleTiming;
private float StartTime;
private bool CurrentlyTiming = false;
private void Awake() {
ToggleTiming = new InputAction("Toggle stopwatch", binding: "<Keyboard>/t");
ToggleTiming.performed += _ => {
if (CurrentlyTiming) {
UpdateTiming();
CurrentlyTiming = false;
} else {
StartTime = Time.fixedTime;
CurrentlyTiming = true;
}
};
ToggleTiming.Enable();
}
private void FixedUpdate() {
if (CurrentlyTiming) {
UpdateTiming();
}
}
private void UpdateTiming() {
float Duration = Time.fixedTime - StartTime;
TimingText.text = Duration.ToString("0.00") + " s";
}
}
}

View File

@ -95,7 +95,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet;
if (Players[conn.uid].Controlled != null) {
syncPckt.PlayerId = conn.uid;
if (!Players[conn.uid].Controlled.ProcessSyncPacket(syncPckt)) {
if (!Players[conn.uid].Controlled.ProcessSyncPacket(syncPckt, false)) {
Players[conn.uid].Unsynced = true;
}
}

View File

@ -1,6 +1,6 @@
using UnityEngine;
using NeonTea.Quakeball.Networking.Packets;
using NeonTea.Quakeball.Interface;
using NeonTea.Quakeball.Util;
namespace NeonTea.Quakeball.Players {
/// <summary>The central glue class for players (both local and remote).</summary>
@ -21,6 +21,9 @@ namespace NeonTea.Quakeball.Players {
public Transform Gun;
public Animator GunBobber;
[Header("Visuals")]
public DesyncLerper[] Lerpables;
[Header("Player rotation status")]
/// <summary>The pitch of the player's head.</summary>
public float Pitch;
@ -91,6 +94,13 @@ namespace NeonTea.Quakeball.Players {
ShouldApply = true;
}
if (ShouldApply) {
Vector3 Delta = transform.position - syncPckt.Location;
if (Delta.magnitude < 1) {
// Player is close enough to the sync packet, lerp them over.
foreach (DesyncLerper Lerper in Lerpables) {
Lerper.Offset(Delta);
}
}
transform.position = syncPckt.Location;
GroundVelocity = syncPckt.GroundVelocity;
}

View File

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NeonTea.Quakeball.Util {
/// <summary>Used to offset visual parts of violently re-synced objects, so they can be smoothly lerped back to reality.</summary>
public class DesyncLerper : MonoBehaviour {
public float Speed = 1;
private Vector3 OffsetLeft;
public void Offset(Vector3 offset) {
transform.position += offset;
OffsetLeft += offset;
}
private void Update() {
Vector3 NewPosition = Vector3.Lerp(transform.position, transform.position - OffsetLeft, Speed * Time.deltaTime);
OffsetLeft += NewPosition - transform.position;
transform.position = NewPosition;
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 61e1b888bc9173449923055928c4d73d
guid: c0e8b530a9e9275419a275e5557a0420
MonoImporter:
externalObjects: {}
serializedVersion: 2