diff --git a/Assets/GameFlowManager.cs b/Assets/GameFlowManager.cs index a8ad5f2..3a24fd4 100644 --- a/Assets/GameFlowManager.cs +++ b/Assets/GameFlowManager.cs @@ -3,6 +3,10 @@ using UnityEngine.InputSystem; //Could be a singleton public class GameFlowManager : MonoBehaviour { + /// + /// True if time is frozen (Start, Pause Menu, Dead) + /// + /// Could be renamed appropriately [field: SerializeField] public bool Paused { get; private set; } = true; public BaseState CurrentState { get; private set; } = null!; diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index a1aaa4d..de73b9d 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -51,10 +51,10 @@ public class Entity : MonoBehaviour } protected virtual void MoveToTarget(){ - + //Would be nice if we could force this to be in FixedUpdate direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*Time.fixedDeltaTime, 0.0f); if(!IsInAttackRange()){ - rb.MovePosition(transform.position + direction * movementSpeed * deltaTime); + rb.MovePosition(transform.position + direction * movementSpeed * Time.fixedDeltaTime); } } diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index e0ac5b2..431f005 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -21,10 +21,11 @@ public class PlayerMovement : MonoBehaviour { bool lastJumpButton; #region Unity Messages - void Awake(){ + + void Awake() { rb = GetComponent(); currentState = new ImmobileMovementState(this); - } + } void Start() => currentState.EnterState(); @@ -65,7 +66,7 @@ public class PlayerMovement : MonoBehaviour { if (!wasJustPressed) return; - if (safeZone == null) + if (gameFlowManager.Paused || safeZone == null) return; if (safeZone.IsInSafeZone) { @@ -113,16 +114,15 @@ public class PlayerMovement : MonoBehaviour { abstract class BaseStatePlayerMovement : BaseState { protected PlayerMovement playerMovement; - public BaseStatePlayerMovement(PlayerMovement playerMovement){ + + public BaseStatePlayerMovement(PlayerMovement playerMovement) { this.playerMovement = playerMovement; } } class NormalMovementState : BaseStatePlayerMovement { - public NormalMovementState(PlayerMovement playerMovement) : base(playerMovement){ + public NormalMovementState(PlayerMovement playerMovement) : base(playerMovement) {} - } - public override BaseState? FixedUpdateState() { playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.stats.movementSpeed; @@ -167,17 +167,18 @@ public class PlayerMovement : MonoBehaviour { class EnterSafeZoneMovementState : JumpingMovementState { readonly SafeZone safeZone; + public EnterSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.transform.position) { this.safeZone = safeZone; } public override void EnterState() { base.EnterState(); - + safeZone.EnterSafeZone(); playerMovement.SetRigidbodyEnabled(false); } - + protected override BaseState Transition() => new ImmobileMovementState(playerMovement); protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t); @@ -185,13 +186,14 @@ public class PlayerMovement : MonoBehaviour { class ExitSafeZoneMovementState : JumpingMovementState { readonly SafeZone safeZone; + public ExitSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone, Vector2 direction) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) { this.safeZone = safeZone; } public override void LeaveState() { base.EnterState(); - + safeZone.ExitSafeZone(); playerMovement.SetRigidbodyEnabled(true); } @@ -200,12 +202,10 @@ public class PlayerMovement : MonoBehaviour { } class ImmobileMovementState : BaseStatePlayerMovement { - public ImmobileMovementState(PlayerMovement playerMovement) : base(playerMovement){ - - } + public ImmobileMovementState(PlayerMovement playerMovement) : base(playerMovement) {} public override void EnterState() { base.EnterState(); - + if (!playerMovement.rb.isKinematic) Debug.LogWarning("Rigidbody should probably be kinematic when immobile (when in safe zone)."); }