Hi everyone after watching lots of youtube and googling about 10,000 things I’m a little confused on state machines. On the code below, I am unsure how to break out of states and go into other states when it comes to my movement script.
If I initiate PlayerMovement() on my idle state to enable walking, it just switches to State.Moving then completely stops my character’s ability to move.
protected virtual void Update()
{
IframeAnimation();
GatherMovementData();
switch (state)
{
case State.Idle:
break;
case State.Moving:
Dash();
ActivateAttack();
MovementAnimation();
break;
}
}
protected virtual void FixedUpdate()
{
switch (state)
{
case State.Moving:
StartCoroutine(PlayerMovement());
break;
}
}
private IEnumerator PlayerMovement()
{
state = State.Moving;
if (isAlive && !Input.GetKey(KeyCode.Space) && knockedBack == false)
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
if (!isAlive)
yield return new WaitForSeconds(0f);
}