fix player movement and falling cycle

This commit is contained in:
Vladimir Koshevarov
2022-12-13 13:16:27 +02:00
parent 5e778f81d7
commit ccb927ba61
+12 -10
View File
@@ -27,12 +27,12 @@ public class PlayerManager : MonoBehaviour
private void OnEnable()
{
TimeManager.OnMinuteChanged += DecreaseEnergy;
TimeManager.OnMinuteChanged += UpdatePlayerState;
}
private void OnDisable()
{
TimeManager.OnMinuteChanged -= DecreaseEnergy;
TimeManager.OnMinuteChanged -= UpdatePlayerState;
}
// Start is called before the first frame update
@@ -68,18 +68,20 @@ public class PlayerManager : MonoBehaviour
Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero;
var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius;
if (_state != States.Sleeping)
{
_state = shouldMove ? States.Walking : States.Idle;
_state = shouldMove ? States.Walking : States.Idle;
_animator.SetBool("Move", shouldMove);
_animator.SetFloat("velY", velocity.y);
_animator.SetBool("Move", shouldMove);
_animator.SetFloat("velY", velocity.y);
}
}
private void OnAnimatorMove()
{
transform.position = _navAgent.nextPosition;
}
public void DecreaseEnergy()
public void UpdatePlayerState()
{
PlayerStats[StatsId.Food].deduct(0.034m); // 48 hours it's 100, 100/2880=~0.034 per minute
switch (_state)
@@ -96,13 +98,13 @@ public class PlayerManager : MonoBehaviour
{
_state = States.Sleeping;
allowMovement = false;
_animator.SetBool("IsSleeping", true);
_animator.SetBool("Fall", true);
}
if (PlayerStats[StatsId.Energy].Value >= 100 && _state == States.Sleeping)
{
_state = States.Idle;
allowMovement = false;
_animator.SetBool("IsSleeping", false);
allowMovement = true;
_animator.SetBool("Fall", false);
}
}