Fixed flakiness on safezone hopping
This commit is contained in:
parent
d57eab3e92
commit
ba164e5961
@ -578,6 +578,10 @@ PrefabInstance:
|
||||
propertyPath: m_ActionEvents.Array.data[16].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
|
||||
value: UnityEngine.Object, UnityEngine
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||
propertyPath: globalCamera
|
||||
value:
|
||||
objectReference: {fileID: 1557338110}
|
||||
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||
propertyPath: gameFlowManager
|
||||
value:
|
||||
|
||||
@ -10,6 +10,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
[SerializeField] [field: Required]
|
||||
PlayerStats stats = null!;
|
||||
[SerializeField] GameObject globalCamera;
|
||||
|
||||
[field: Required]
|
||||
Rigidbody2D rb = null!;
|
||||
@ -20,6 +21,8 @@ public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
bool lastJumpButton;
|
||||
|
||||
public bool IsInSafeZone => currentState is ImmobileMovementState;
|
||||
|
||||
#region Unity Messages
|
||||
|
||||
void Awake() {
|
||||
@ -27,7 +30,10 @@ public class PlayerMovement : MonoBehaviour {
|
||||
currentState = new ImmobileMovementState(this);
|
||||
}
|
||||
|
||||
void Start() => currentState.EnterState();
|
||||
void Start() {
|
||||
globalCamera.SetActive(true);
|
||||
currentState.EnterState();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (gameFlowManager.Paused)
|
||||
@ -68,10 +74,10 @@ public class PlayerMovement : MonoBehaviour {
|
||||
if (gameFlowManager.Paused || safeZone == null)
|
||||
return;
|
||||
|
||||
if (safeZone.IsInSafeZone) {
|
||||
if (IsInSafeZone) {
|
||||
if (moveDirection.magnitude >= safeZone.Stats.MinJumpJoystickValue)
|
||||
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));
|
||||
}
|
||||
|
||||
@ -104,12 +110,6 @@ public class PlayerMovement : MonoBehaviour {
|
||||
currentState = newState;
|
||||
newState.EnterState();
|
||||
}
|
||||
public bool IsInSafeZone(){
|
||||
if(safeZone is null){
|
||||
return false;
|
||||
}
|
||||
return safeZone.IsInSafeZone;
|
||||
}
|
||||
|
||||
abstract class BaseStatePlayerMovement : BaseState {
|
||||
protected PlayerMovement playerMovement;
|
||||
@ -174,7 +174,6 @@ public class PlayerMovement : MonoBehaviour {
|
||||
public override void EnterState() {
|
||||
base.EnterState();
|
||||
|
||||
safeZone.EnterSafeZone();
|
||||
playerMovement.rb.SetEnabled(false);
|
||||
}
|
||||
|
||||
@ -193,7 +192,6 @@ public class PlayerMovement : MonoBehaviour {
|
||||
public override void LeaveState() {
|
||||
base.EnterState();
|
||||
|
||||
safeZone.ExitSafeZone();
|
||||
playerMovement.rb.SetEnabled(true);
|
||||
}
|
||||
|
||||
@ -205,9 +203,17 @@ public class PlayerMovement : MonoBehaviour {
|
||||
public override void EnterState() {
|
||||
base.EnterState();
|
||||
|
||||
playerMovement.globalCamera.SetActive(true);
|
||||
if (!playerMovement.rb.isKinematic)
|
||||
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
|
||||
public override void OnDrawGizmos() {
|
||||
if (playerMovement.safeZone is null)
|
||||
|
||||
@ -6,23 +6,6 @@ public class SafeZone : MonoBehaviour {
|
||||
public SafeZoneStats Stats { get; private set; }
|
||||
|
||||
[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) {
|
||||
return transform.position + (moatCollider.radius + Stats.JumpOffset) * (Vector3)direction;
|
||||
|
||||
@ -29,12 +29,7 @@ public class VampireEntity : Entity {
|
||||
// healthBar.SetHealthFraction(Health / initialHealth);
|
||||
// }
|
||||
|
||||
public bool IsInSafeZone(){
|
||||
if(playerMovement is null){
|
||||
return false;
|
||||
}
|
||||
return playerMovement.IsInSafeZone();
|
||||
}
|
||||
public bool IsInSafeZone() => playerMovement.IsInSafeZone;
|
||||
|
||||
protected override void OnDied() => gameFlowManager.GameOver();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user