fix player movement and falling cycle
This commit is contained in:
@@ -27,12 +27,12 @@ public class PlayerManager : MonoBehaviour
|
|||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
TimeManager.OnMinuteChanged += DecreaseEnergy;
|
TimeManager.OnMinuteChanged += UpdatePlayerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisable()
|
private void OnDisable()
|
||||||
{
|
{
|
||||||
TimeManager.OnMinuteChanged -= DecreaseEnergy;
|
TimeManager.OnMinuteChanged -= UpdatePlayerState;
|
||||||
}
|
}
|
||||||
// Start is called before the first frame update
|
// 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;
|
Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero;
|
||||||
var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius;
|
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()
|
private void OnAnimatorMove()
|
||||||
{
|
{
|
||||||
transform.position = _navAgent.nextPosition;
|
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
|
PlayerStats[StatsId.Food].deduct(0.034m); // 48 hours it's 100, 100/2880=~0.034 per minute
|
||||||
switch (_state)
|
switch (_state)
|
||||||
@@ -96,13 +98,13 @@ public class PlayerManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
_state = States.Sleeping;
|
_state = States.Sleeping;
|
||||||
allowMovement = false;
|
allowMovement = false;
|
||||||
_animator.SetBool("IsSleeping", true);
|
_animator.SetBool("Fall", true);
|
||||||
}
|
}
|
||||||
if (PlayerStats[StatsId.Energy].Value >= 100 && _state == States.Sleeping)
|
if (PlayerStats[StatsId.Energy].Value >= 100 && _state == States.Sleeping)
|
||||||
{
|
{
|
||||||
_state = States.Idle;
|
_state = States.Idle;
|
||||||
allowMovement = false;
|
allowMovement = true;
|
||||||
_animator.SetBool("IsSleeping", false);
|
_animator.SetBool("Fall", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user