first implementation of freeze

This commit is contained in:
Novvator 2021-03-08 14:16:20 +00:00
parent 2b3a950208
commit 660569601d
14 changed files with 188 additions and 27 deletions

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c2e37ff6639a22e4eacc5e95d8e13723
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2538,11 +2538,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.017264403 value: -0.017264389
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.009297725 value: 0.009297717
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@ -2558,19 +2558,19 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.9680315 value: 0.9663801
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0.24655113 value: 0.24613053
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.044697862 value: 0.07205816
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.011384245 value: -0.018352732
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633831414007564, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633831414007564, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_Name propertyPath: m_Name
@ -2624,6 +2624,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 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} - target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: _cheatBlink propertyPath: _cheatBlink
value: 0 value: 0
@ -2632,6 +2636,22 @@ PrefabInstance:
propertyPath: _cheatBoost propertyPath: _cheatBoost
value: 0 value: 0
objectReference: {fileID: 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} - target: {fileID: 4676633831945762708, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_Height propertyPath: m_Height
value: 1.5 value: 1.5
@ -2662,11 +2682,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.017264403 value: -0.017264389
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.009297725 value: 0.009297717
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_XAxis.m_InvertInput propertyPath: m_XAxis.m_InvertInput
@ -2702,19 +2722,19 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.9996367 value: 0.9984866
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0.0047711134 value: 0.0047656302
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.023356276 value: 0.048239034
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.0125784995 value: -0.02597908
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
@ -7364,6 +7384,7 @@ MonoBehaviour:
inputSettings: {fileID: 11400000, guid: 87faf39b6f22e524984c1680a88045ac, type: 2} inputSettings: {fileID: 11400000, guid: 87faf39b6f22e524984c1680a88045ac, type: 2}
dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2} dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2}
artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2} artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2}
playerTimeScale: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2}
--- !u!114 &2070784759 --- !u!114 &2070784759
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -16,6 +16,7 @@ public class PickUpDisplay : MonoBehaviour
[SerializeField] private InputSettings inputSettings; [SerializeField] private InputSettings inputSettings;
[SerializeField] private DialogueSystem dialogue; [SerializeField] private DialogueSystem dialogue;
[SerializeField] private ArtefactSystem artefacts; [SerializeField] private ArtefactSystem artefacts;
[SerializeField] private SerialFloat playerTimeScale;
private Artefact chosenArtefact; private Artefact chosenArtefact;
@ -35,22 +36,24 @@ public class PickUpDisplay : MonoBehaviour
public void PopUpOn() public void PopUpOn()
{ {
_paused = true; _paused = true;
artefactUI.SetActive(true); //artefactUI.SetActive(true);
Player.GetComponent<PlayerInput>().enabled = false; //Player.GetComponent<PlayerInput>().enabled = false;
artefactText.text = "You have unlocked " + chosenArtefact.Name + "!"; artefactText.text = "You have unlocked " + chosenArtefact.Name + "!";
inputSettings.updateMode = (InputSettings.UpdateMode)1; //inputSettings.updateMode = (InputSettings.UpdateMode)1;
Time.timeScale = 0f; Time.timeScale = 0f;
//playerTimeScale.Value = 0f;
} }
public void PopUpOff() public void PopUpOff()
{ {
_paused = false; _paused = false;
artefactUI.SetActive(false); //artefactUI.SetActive(false);
inputSettings.updateMode = (InputSettings.UpdateMode)2; //inputSettings.updateMode = (InputSettings.UpdateMode)2;
Player.GetComponent<PlayerInput>().enabled = true; //Player.GetComponent<PlayerInput>().enabled = true;
Time.timeScale = 1.0f; Time.timeScale = 1.0f;
//playerTimeScale.Value = 1.0f;
dialogue.PlayLine(chosenArtefact.dialogueKey); //dialogue.PlayLine(chosenArtefact.dialogueKey);
chosenArtefact = null; chosenArtefact = null;
} }
} }

View File

@ -1,6 +1,7 @@
using Extensions; using Extensions;
using UnityEngine; using UnityEngine;
using NaughtyAttributes; using NaughtyAttributes;
using Ktyl.Util;
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour
{ {
@ -68,6 +69,10 @@ public class PlayerController : MonoBehaviour
private const float TAU = Mathf.PI * 2f; private const float TAU = Mathf.PI * 2f;
private const float HALF_PI = Mathf.PI / 2f; private const float HALF_PI = Mathf.PI / 2f;
[SerializeField]
private SerialFloat playerTimeScale;
private enum JumpState private enum JumpState
{ {
None, 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) private void UpdateJump(float dt)
{ {
_fallTime = _grounded ? 0f : (_fallTime + dt); _fallTime = _grounded ? 0f : (_fallTime + dt);
@ -257,7 +273,7 @@ public class PlayerController : MonoBehaviour
private void FixedUpdate() private void FixedUpdate()
{ {
float dt = Time.fixedDeltaTime; float dt = Time.fixedUnscaledDeltaTime * playerTimeScale;
_overrideDelta = Vector2.zero; _overrideDelta = Vector2.zero;
@ -273,6 +289,7 @@ public class PlayerController : MonoBehaviour
UpdateJump( dt ); UpdateJump( dt );
UpdateLook( dt ); UpdateLook( dt );
UpdateBlink( dt ); UpdateBlink( dt );
//UpdateFreeze( dt );
UpdateGravity( dt ); UpdateGravity( dt );
UpdateDrag( dt ); UpdateDrag( dt );
UpdateMovement( dt ); UpdateMovement( dt );

View File

@ -16,20 +16,25 @@ public class PlayerInputHandler : MonoBehaviour
[SerializeField] [SerializeField]
private Camera _camera; private Camera _camera;
[SerializeField]
private SerialFloat playerTimeScale;
public class PlayerInputState public class PlayerInputState
{ {
public BufferedInput Jump; public BufferedInput Jump;
public BufferedInput Blink; public BufferedInput Blink;
public BufferedInput Use; public BufferedInput Use;
public BufferedInput Freeze;
public CameraRelativeInput Move; public CameraRelativeInput Move;
public Vector2 Look; public Vector2 Look;
public float MoveRotation; 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 ); Jump = new BufferedInput( jumpBuffer );
Blink = new BufferedInput( blinkBuffer ); Blink = new BufferedInput( blinkBuffer );
Use = new BufferedInput( useBuffer ); Use = new BufferedInput( useBuffer );
Freeze = new BufferedInput( freezeBuffer );
Move = new CameraRelativeInput(); Move = new CameraRelativeInput();
Look = Vector2.zero; Look = Vector2.zero;
} }
@ -39,6 +44,7 @@ public class PlayerInputHandler : MonoBehaviour
Jump.Update(deltaTime); Jump.Update(deltaTime);
Blink.Update(deltaTime); Blink.Update(deltaTime);
Use.Update(deltaTime); Use.Update(deltaTime);
Freeze.Update(deltaTime);
} }
} }
@ -51,13 +57,14 @@ public class PlayerInputHandler : MonoBehaviour
_state = new PlayerInputState( _state = new PlayerInputState(
_inputSettings.JumpBufferTime, _inputSettings.JumpBufferTime,
_inputSettings.BlinkBufferTime, _inputSettings.BlinkBufferTime,
_inputSettings.UseBufferTime _inputSettings.UseBufferTime,
); _inputSettings.FreezeBufferTime
) ;
} }
private void FixedUpdate() private void FixedUpdate()
{ {
_state.Update( Time.fixedDeltaTime ); _state.Update( Time.fixedDeltaTime);
float cameraRotation = _camera.transform.rotation.eulerAngles.y; float cameraRotation = _camera.transform.rotation.eulerAngles.y;
_state.Move.SetAngle(-cameraRotation); _state.Move.SetAngle(-cameraRotation);
@ -85,4 +92,10 @@ public class PlayerInputHandler : MonoBehaviour
if(context.started) if(context.started)
EventHandler.current.ArtefactPickUp(_nearbyArtefactID.Value); EventHandler.current.ArtefactPickUp(_nearbyArtefactID.Value);
} }
public void Freeze(InputAction.CallbackContext context)
{
_state.Freeze.Set( context.ReadValueAsButton() );
}
} }

View File

@ -8,6 +8,7 @@ public class PlayerInputSettings : ScriptableObject
public float JumpBufferTime => _jumpBufferTime; public float JumpBufferTime => _jumpBufferTime;
public float BlinkBufferTime => _blinkBufferTime; public float BlinkBufferTime => _blinkBufferTime;
public float UseBufferTime => _useBufferTime; public float UseBufferTime => _useBufferTime;
public float FreezeBufferTime => _freezeBufferTime;
[SerializeField] [SerializeField]
private float _jumpBufferTime; private float _jumpBufferTime;
@ -17,4 +18,7 @@ public class PlayerInputSettings : ScriptableObject
[SerializeField] [SerializeField]
private float _useBufferTime; private float _useBufferTime;
[SerializeField]
private float _freezeBufferTime;
} }

View File

@ -12,6 +12,9 @@ public class PlayerPowers : MonoBehaviour
[SerializeField] [SerializeField]
private bool _cheatBoost; private bool _cheatBoost;
[SerializeField]
private bool _cheatFreeze;
[Header( "References" )] [Header( "References" )]
[SerializeField] [SerializeField]
private PlayerPower _blink; private PlayerPower _blink;
@ -19,12 +22,17 @@ public class PlayerPowers : MonoBehaviour
[SerializeField] [SerializeField]
private PlayerPower _boost; private PlayerPower _boost;
[SerializeField]
private PlayerPower _freeze;
public PlayerPower Blink => _blink; public PlayerPower Blink => _blink;
public PlayerPower Boost => _boost; public PlayerPower Boost => _boost;
public PlayerPower Freeze => _freeze;
public void UpdatePowers( float dt, bool grounded ) public void UpdatePowers( float dt, bool grounded )
{ {
_blink.UpdatePower( dt, _cheatBlink, grounded ); _blink.UpdatePower( dt, _cheatBlink, grounded );
_boost.UpdatePower( dt, _cheatBoost, grounded ); _boost.UpdatePower( dt, _cheatBoost, grounded );
_boost.UpdatePower(dt, _cheatFreeze, grounded);
} }
} }

View File

@ -44,6 +44,14 @@
"expectedControlType": "Button", "expectedControlType": "Button",
"processors": "", "processors": "",
"interactions": "" "interactions": ""
},
{
"name": "Freeze",
"type": "Button",
"id": "29f1599e-fe43-47df-ad25-8e712263d0ab",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
} }
], ],
"bindings": [ "bindings": [
@ -200,6 +208,17 @@
"action": "Blink", "action": "Blink",
"isComposite": false, "isComposite": false,
"isPartOfComposite": false "isPartOfComposite": false
},
{
"name": "",
"id": "8c9e09a3-477e-4760-bdba-f81beaec4988",
"path": "<Keyboard>/g",
"interactions": "",
"processors": "",
"groups": "PCMR",
"action": "Freeze",
"isComposite": false,
"isPartOfComposite": false
} }
] ]
} }

View File

@ -15,3 +15,4 @@ MonoBehaviour:
_jumpBufferTime: 0.1 _jumpBufferTime: 0.1
_blinkBufferTime: 0.1 _blinkBufferTime: 0.1
_useBufferTime: 0.1 _useBufferTime: 0.1
_freezeBufferTime: 2

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0cd9cf6494bb6f54d9b97631010d780e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 39c05ba9d0743074b9eb0e561ba1fcb8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: