From 660569601d3304e787b7e593a81058890613d4d9 Mon Sep 17 00:00:00 2001 From: Novvator Date: Mon, 8 Mar 2021 14:16:20 +0000 Subject: [PATCH] first implementation of freeze --- .../ArtefactObjects/Power/PA_Freeze.asset | 18 ++++++++ .../Power/PA_Freeze.asset.meta | 8 ++++ game/Assets/Scenes/Main.unity | 45 ++++++++++++++----- .../Assets/Scripts/Artefacts/PickUpDisplay.cs | 17 ++++--- .../Assets/Scripts/Player/PlayerController.cs | 19 +++++++- .../Scripts/Player/PlayerInputHandler.cs | 27 ++++++++--- .../Scripts/Player/PlayerInputSettings.cs | 4 ++ game/Assets/Scripts/Player/PlayerPowers.cs | 8 ++++ .../Input/PlayerControls.inputactions | 19 ++++++++ .../Settings/Player/PlayerInputSettings.asset | 1 + .../Settings/Player/Powers/Freeze.asset | 17 +++++++ .../Settings/Player/Powers/Freeze.asset.meta | 8 ++++ .../Player/Powers/playerTimeScale.asset | 16 +++++++ .../Player/Powers/playerTimeScale.asset.meta | 8 ++++ 14 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset create mode 100644 game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset.meta create mode 100644 game/Assets/Settings/Player/Powers/Freeze.asset create mode 100644 game/Assets/Settings/Player/Powers/Freeze.asset.meta create mode 100644 game/Assets/Settings/Player/Powers/playerTimeScale.asset create mode 100644 game/Assets/Settings/Player/Powers/playerTimeScale.asset.meta diff --git a/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset b/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset new file mode 100644 index 0000000..82e4056 --- /dev/null +++ b/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0228856d50ce2a845abd7b3eda114390, type: 3} + m_Name: PA_Freeze + m_EditorClassIdentifier: + _artefactID: 12 + _dialogueKey: + _name: Freeze + _power: {fileID: 0} diff --git a/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset.meta b/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset.meta new file mode 100644 index 0000000..067ac7e --- /dev/null +++ b/game/Assets/Data/Artefacts/ArtefactObjects/Power/PA_Freeze.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c2e37ff6639a22e4eacc5e95d8e13723 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/game/Assets/Scenes/Main.unity b/game/Assets/Scenes/Main.unity index f9d2d8a..5fd82a7 100644 --- a/game/Assets/Scenes/Main.unity +++ b/game/Assets/Scenes/Main.unity @@ -2538,11 +2538,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: -0.017264403 + value: -0.017264389 objectReference: {fileID: 0} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: 0.009297725 + value: 0.009297717 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalPosition.x @@ -2558,19 +2558,19 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.w - value: 0.9680315 + value: 0.9663801 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.24655113 + value: 0.24613053 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: 0.044697862 + value: 0.07205816 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: -0.011384245 + value: -0.018352732 objectReference: {fileID: 0} - target: {fileID: 4676633831414007564, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_Name @@ -2624,6 +2624,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: _freeze + value: + objectReference: {fileID: 11400000, guid: 0cd9cf6494bb6f54d9b97631010d780e, type: 2} - target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: _cheatBlink value: 0 @@ -2632,6 +2636,22 @@ PrefabInstance: propertyPath: _cheatBoost value: 0 objectReference: {fileID: 0} + - target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: _cheatFreeze + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4676633831945762665, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: m_DefaultControlScheme + value: PCMR + objectReference: {fileID: 0} + - target: {fileID: 4676633831945762666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: playerTimeScale + value: + objectReference: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2} + - target: {fileID: 4676633831945762667, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: playerTimeScale + value: + objectReference: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2} - target: {fileID: 4676633831945762708, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_Height value: 1.5 @@ -2662,11 +2682,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: -0.017264403 + value: -0.017264389 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: 0.009297725 + value: 0.009297717 objectReference: {fileID: 0} - target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_XAxis.m_InvertInput @@ -2702,19 +2722,19 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.w - value: 0.9996367 + value: 0.9984866 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.0047711134 + value: 0.0047656302 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: 0.023356276 + value: 0.048239034 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: -0.0125784995 + value: -0.02597908 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} @@ -7364,6 +7384,7 @@ MonoBehaviour: inputSettings: {fileID: 11400000, guid: 87faf39b6f22e524984c1680a88045ac, type: 2} dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2} artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2} + playerTimeScale: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2} --- !u!114 &2070784759 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/game/Assets/Scripts/Artefacts/PickUpDisplay.cs b/game/Assets/Scripts/Artefacts/PickUpDisplay.cs index 34781be..c0271ab 100644 --- a/game/Assets/Scripts/Artefacts/PickUpDisplay.cs +++ b/game/Assets/Scripts/Artefacts/PickUpDisplay.cs @@ -16,6 +16,7 @@ public class PickUpDisplay : MonoBehaviour [SerializeField] private InputSettings inputSettings; [SerializeField] private DialogueSystem dialogue; [SerializeField] private ArtefactSystem artefacts; + [SerializeField] private SerialFloat playerTimeScale; private Artefact chosenArtefact; @@ -35,22 +36,24 @@ public class PickUpDisplay : MonoBehaviour public void PopUpOn() { _paused = true; - artefactUI.SetActive(true); - Player.GetComponent().enabled = false; + //artefactUI.SetActive(true); + //Player.GetComponent().enabled = false; artefactText.text = "You have unlocked " + chosenArtefact.Name + "!"; - inputSettings.updateMode = (InputSettings.UpdateMode)1; + //inputSettings.updateMode = (InputSettings.UpdateMode)1; Time.timeScale = 0f; + //playerTimeScale.Value = 0f; } public void PopUpOff() { _paused = false; - artefactUI.SetActive(false); - inputSettings.updateMode = (InputSettings.UpdateMode)2; - Player.GetComponent().enabled = true; + //artefactUI.SetActive(false); + //inputSettings.updateMode = (InputSettings.UpdateMode)2; + //Player.GetComponent().enabled = true; Time.timeScale = 1.0f; + //playerTimeScale.Value = 1.0f; - dialogue.PlayLine(chosenArtefact.dialogueKey); + //dialogue.PlayLine(chosenArtefact.dialogueKey); chosenArtefact = null; } } diff --git a/game/Assets/Scripts/Player/PlayerController.cs b/game/Assets/Scripts/Player/PlayerController.cs index c62724e..eeff8a6 100644 --- a/game/Assets/Scripts/Player/PlayerController.cs +++ b/game/Assets/Scripts/Player/PlayerController.cs @@ -1,6 +1,7 @@ using Extensions; using UnityEngine; using NaughtyAttributes; +using Ktyl.Util; public class PlayerController : MonoBehaviour { @@ -68,6 +69,10 @@ public class PlayerController : MonoBehaviour private const float TAU = Mathf.PI * 2f; private const float HALF_PI = Mathf.PI / 2f; + + [SerializeField] + private SerialFloat playerTimeScale; + private enum JumpState { None, @@ -149,6 +154,17 @@ public class PlayerController : MonoBehaviour } } + + /*private void UpdateFreeze( float dt) + { + if( _powers.Freeze.CanConsume ) + { + Time.timeScale = 0f; + _powers.Freeze.Consume(); + } + } + */ + private void UpdateJump(float dt) { _fallTime = _grounded ? 0f : (_fallTime + dt); @@ -257,7 +273,7 @@ public class PlayerController : MonoBehaviour private void FixedUpdate() { - float dt = Time.fixedDeltaTime; + float dt = Time.fixedUnscaledDeltaTime * playerTimeScale; _overrideDelta = Vector2.zero; @@ -273,6 +289,7 @@ public class PlayerController : MonoBehaviour UpdateJump( dt ); UpdateLook( dt ); UpdateBlink( dt ); + //UpdateFreeze( dt ); UpdateGravity( dt ); UpdateDrag( dt ); UpdateMovement( dt ); diff --git a/game/Assets/Scripts/Player/PlayerInputHandler.cs b/game/Assets/Scripts/Player/PlayerInputHandler.cs index e844d6f..ee112d7 100644 --- a/game/Assets/Scripts/Player/PlayerInputHandler.cs +++ b/game/Assets/Scripts/Player/PlayerInputHandler.cs @@ -16,20 +16,25 @@ public class PlayerInputHandler : MonoBehaviour [SerializeField] private Camera _camera; + [SerializeField] + private SerialFloat playerTimeScale; + public class PlayerInputState { public BufferedInput Jump; public BufferedInput Blink; public BufferedInput Use; + public BufferedInput Freeze; public CameraRelativeInput Move; public Vector2 Look; public float MoveRotation; - public PlayerInputState( float jumpBuffer, float blinkBuffer, float useBuffer ) + public PlayerInputState( float jumpBuffer, float blinkBuffer, float useBuffer , float freezeBuffer) { Jump = new BufferedInput( jumpBuffer ); Blink = new BufferedInput( blinkBuffer ); Use = new BufferedInput( useBuffer ); + Freeze = new BufferedInput( freezeBuffer ); Move = new CameraRelativeInput(); Look = Vector2.zero; } @@ -39,6 +44,7 @@ public class PlayerInputHandler : MonoBehaviour Jump.Update(deltaTime); Blink.Update(deltaTime); Use.Update(deltaTime); + Freeze.Update(deltaTime); } } @@ -48,16 +54,17 @@ public class PlayerInputHandler : MonoBehaviour private void Awake() { - _state = new PlayerInputState( - _inputSettings.JumpBufferTime, - _inputSettings.BlinkBufferTime, - _inputSettings.UseBufferTime - ); + _state = new PlayerInputState( + _inputSettings.JumpBufferTime, + _inputSettings.BlinkBufferTime, + _inputSettings.UseBufferTime, + _inputSettings.FreezeBufferTime + ) ; } private void FixedUpdate() { - _state.Update( Time.fixedDeltaTime ); + _state.Update( Time.fixedDeltaTime); float cameraRotation = _camera.transform.rotation.eulerAngles.y; _state.Move.SetAngle(-cameraRotation); @@ -85,4 +92,10 @@ public class PlayerInputHandler : MonoBehaviour if(context.started) EventHandler.current.ArtefactPickUp(_nearbyArtefactID.Value); } + + public void Freeze(InputAction.CallbackContext context) + { + _state.Freeze.Set( context.ReadValueAsButton() ); + + } } \ No newline at end of file diff --git a/game/Assets/Scripts/Player/PlayerInputSettings.cs b/game/Assets/Scripts/Player/PlayerInputSettings.cs index 68f8415..d3409f6 100644 --- a/game/Assets/Scripts/Player/PlayerInputSettings.cs +++ b/game/Assets/Scripts/Player/PlayerInputSettings.cs @@ -8,6 +8,7 @@ public class PlayerInputSettings : ScriptableObject public float JumpBufferTime => _jumpBufferTime; public float BlinkBufferTime => _blinkBufferTime; public float UseBufferTime => _useBufferTime; + public float FreezeBufferTime => _freezeBufferTime; [SerializeField] private float _jumpBufferTime; @@ -17,4 +18,7 @@ public class PlayerInputSettings : ScriptableObject [SerializeField] private float _useBufferTime; + + [SerializeField] + private float _freezeBufferTime; } diff --git a/game/Assets/Scripts/Player/PlayerPowers.cs b/game/Assets/Scripts/Player/PlayerPowers.cs index 8ddb7fa..d222841 100644 --- a/game/Assets/Scripts/Player/PlayerPowers.cs +++ b/game/Assets/Scripts/Player/PlayerPowers.cs @@ -12,6 +12,9 @@ public class PlayerPowers : MonoBehaviour [SerializeField] private bool _cheatBoost; + [SerializeField] + private bool _cheatFreeze; + [Header( "References" )] [SerializeField] private PlayerPower _blink; @@ -19,12 +22,17 @@ public class PlayerPowers : MonoBehaviour [SerializeField] private PlayerPower _boost; + [SerializeField] + private PlayerPower _freeze; + public PlayerPower Blink => _blink; public PlayerPower Boost => _boost; + public PlayerPower Freeze => _freeze; public void UpdatePowers( float dt, bool grounded ) { _blink.UpdatePower( dt, _cheatBlink, grounded ); _boost.UpdatePower( dt, _cheatBoost, grounded ); + _boost.UpdatePower(dt, _cheatFreeze, grounded); } } \ No newline at end of file diff --git a/game/Assets/Settings/Input/PlayerControls.inputactions b/game/Assets/Settings/Input/PlayerControls.inputactions index ffae4f3..657e6cb 100644 --- a/game/Assets/Settings/Input/PlayerControls.inputactions +++ b/game/Assets/Settings/Input/PlayerControls.inputactions @@ -44,6 +44,14 @@ "expectedControlType": "Button", "processors": "", "interactions": "" + }, + { + "name": "Freeze", + "type": "Button", + "id": "29f1599e-fe43-47df-ad25-8e712263d0ab", + "expectedControlType": "Button", + "processors": "", + "interactions": "" } ], "bindings": [ @@ -200,6 +208,17 @@ "action": "Blink", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "8c9e09a3-477e-4760-bdba-f81beaec4988", + "path": "/g", + "interactions": "", + "processors": "", + "groups": "PCMR", + "action": "Freeze", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/game/Assets/Settings/Player/PlayerInputSettings.asset b/game/Assets/Settings/Player/PlayerInputSettings.asset index 6ae14f2..1aeb4d5 100644 --- a/game/Assets/Settings/Player/PlayerInputSettings.asset +++ b/game/Assets/Settings/Player/PlayerInputSettings.asset @@ -15,3 +15,4 @@ MonoBehaviour: _jumpBufferTime: 0.1 _blinkBufferTime: 0.1 _useBufferTime: 0.1 + _freezeBufferTime: 2 diff --git a/game/Assets/Settings/Player/Powers/Freeze.asset b/game/Assets/Settings/Player/Powers/Freeze.asset new file mode 100644 index 0000000..2c64d89 --- /dev/null +++ b/game/Assets/Settings/Player/Powers/Freeze.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 24d28ac60e22b5547b2beb8679625039, type: 3} + m_Name: Freeze + m_EditorClassIdentifier: + _regenerateOnGround: 0 + _regenerateInAir: 0 + _regenerateTime: 0 diff --git a/game/Assets/Settings/Player/Powers/Freeze.asset.meta b/game/Assets/Settings/Player/Powers/Freeze.asset.meta new file mode 100644 index 0000000..7b81e61 --- /dev/null +++ b/game/Assets/Settings/Player/Powers/Freeze.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0cd9cf6494bb6f54d9b97631010d780e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/game/Assets/Settings/Player/Powers/playerTimeScale.asset b/game/Assets/Settings/Player/Powers/playerTimeScale.asset new file mode 100644 index 0000000..b3d57a4 --- /dev/null +++ b/game/Assets/Settings/Player/Powers/playerTimeScale.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 76553ada4233edc458c3fed9b69e128f, type: 3} + m_Name: playerTimeScale + m_EditorClassIdentifier: + _initialValue: 1 + _readOnly: 0 diff --git a/game/Assets/Settings/Player/Powers/playerTimeScale.asset.meta b/game/Assets/Settings/Player/Powers/playerTimeScale.asset.meta new file mode 100644 index 0000000..ed4d209 --- /dev/null +++ b/game/Assets/Settings/Player/Powers/playerTimeScale.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 39c05ba9d0743074b9eb0e561ba1fcb8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: