Fixed flakiness on safezone hopping

This commit is contained in:
Jason Durand 01 2022-04-02 17:52:41 -04:00
parent d57eab3e92
commit ba164e5961
4 changed files with 22 additions and 34 deletions

View File

@ -578,6 +578,10 @@ PrefabInstance:
propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: globalCamera
value:
objectReference: {fileID: 1557338110}
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} - target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: gameFlowManager propertyPath: gameFlowManager
value: value:

View File

@ -10,6 +10,7 @@ public class PlayerMovement : MonoBehaviour {
[SerializeField] [field: Required] [SerializeField] [field: Required]
PlayerStats stats = null!; PlayerStats stats = null!;
[SerializeField] GameObject globalCamera;
[field: Required] [field: Required]
Rigidbody2D rb = null!; Rigidbody2D rb = null!;
@ -20,6 +21,8 @@ public class PlayerMovement : MonoBehaviour {
bool lastJumpButton; bool lastJumpButton;
public bool IsInSafeZone => currentState is ImmobileMovementState;
#region Unity Messages #region Unity Messages
void Awake() { void Awake() {
@ -27,7 +30,10 @@ public class PlayerMovement : MonoBehaviour {
currentState = new ImmobileMovementState(this); currentState = new ImmobileMovementState(this);
} }
void Start() => currentState.EnterState(); void Start() {
globalCamera.SetActive(true);
currentState.EnterState();
}
void Update() { void Update() {
if (gameFlowManager.Paused) if (gameFlowManager.Paused)
@ -68,10 +74,10 @@ public class PlayerMovement : MonoBehaviour {
if (gameFlowManager.Paused || safeZone == null) if (gameFlowManager.Paused || safeZone == null)
return; return;
if (safeZone.IsInSafeZone) { if (IsInSafeZone) {
if (moveDirection.magnitude >= safeZone.Stats.MinJumpJoystickValue) if (moveDirection.magnitude >= safeZone.Stats.MinJumpJoystickValue)
SwitchState(new ExitSafeZoneMovementState(this, safeZone, moveDirection)); SwitchState(new ExitSafeZoneMovementState(this, safeZone, moveDirection));
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90) } else if (currentState is NormalMovementState) //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
SwitchState(new EnterSafeZoneMovementState(this, safeZone)); SwitchState(new EnterSafeZoneMovementState(this, safeZone));
} }
@ -104,12 +110,6 @@ public class PlayerMovement : MonoBehaviour {
currentState = newState; currentState = newState;
newState.EnterState(); newState.EnterState();
} }
public bool IsInSafeZone(){
if(safeZone is null){
return false;
}
return safeZone.IsInSafeZone;
}
abstract class BaseStatePlayerMovement : BaseState { abstract class BaseStatePlayerMovement : BaseState {
protected PlayerMovement playerMovement; protected PlayerMovement playerMovement;
@ -174,7 +174,6 @@ public class PlayerMovement : MonoBehaviour {
public override void EnterState() { public override void EnterState() {
base.EnterState(); base.EnterState();
safeZone.EnterSafeZone();
playerMovement.rb.SetEnabled(false); playerMovement.rb.SetEnabled(false);
} }
@ -193,7 +192,6 @@ public class PlayerMovement : MonoBehaviour {
public override void LeaveState() { public override void LeaveState() {
base.EnterState(); base.EnterState();
safeZone.ExitSafeZone();
playerMovement.rb.SetEnabled(true); playerMovement.rb.SetEnabled(true);
} }
@ -205,9 +203,17 @@ public class PlayerMovement : MonoBehaviour {
public override void EnterState() { public override void EnterState() {
base.EnterState(); base.EnterState();
playerMovement.globalCamera.SetActive(true);
if (!playerMovement.rb.isKinematic) if (!playerMovement.rb.isKinematic)
Debug.LogWarning("Rigidbody should probably be kinematic when immobile (when in safe zone)."); Debug.LogWarning("Rigidbody should probably be kinematic when immobile (when in safe zone).");
} }
public override void LeaveState() {
base.LeaveState();
playerMovement.globalCamera.SetActive(false);
}
#if UNITY_EDITOR #if UNITY_EDITOR
public override void OnDrawGizmos() { public override void OnDrawGizmos() {
if (playerMovement.safeZone is null) if (playerMovement.safeZone is null)

View File

@ -6,23 +6,6 @@ public class SafeZone : MonoBehaviour {
public SafeZoneStats Stats { get; private set; } public SafeZoneStats Stats { get; private set; }
[SerializeField] CircleCollider2D moatCollider; [SerializeField] CircleCollider2D moatCollider;
[SerializeField] GameObject globalCamera;
public bool IsInSafeZone { get; private set; } = true;
void Start() {
globalCamera.SetActive(true);
}
public void EnterSafeZone() {
IsInSafeZone = true;
globalCamera.SetActive(true);
}
public void ExitSafeZone() {
IsInSafeZone = false;
globalCamera.SetActive(false);
}
public Vector3 GetOutsidePosition(Vector2 direction) { public Vector3 GetOutsidePosition(Vector2 direction) {
return transform.position + (moatCollider.radius + Stats.JumpOffset) * (Vector3)direction; return transform.position + (moatCollider.radius + Stats.JumpOffset) * (Vector3)direction;

View File

@ -29,12 +29,7 @@ public class VampireEntity : Entity {
// healthBar.SetHealthFraction(Health / initialHealth); // healthBar.SetHealthFraction(Health / initialHealth);
// } // }
public bool IsInSafeZone(){ public bool IsInSafeZone() => playerMovement.IsInSafeZone;
if(playerMovement is null){
return false;
}
return playerMovement.IsInSafeZone();
}
protected override void OnDied() => gameFlowManager.GameOver(); protected override void OnDied() => gameFlowManager.GameOver();
} }