- Home /
How do I stop character movement when attacking?
Hello I have been trying to solve this problem for some time now and I know that it's a topic that often comes up but the solution tends to be very specific to that particular code.
As the title suggests I want my character to stop moving when the attack animation is being played. I believe a canMove bool is the solution but I am new to coding and have no idea where and how I am supposed to implement it into the code.
The code I'm using does not rely on spider web connections (not sure what the actual name for the lines that connect the animation) in the animator so i'm not sure if that effects how bools are applied.
Here is the movement section of the code.
Vector2 vel = new Vector2(0, rb2d.velocity.y); if (xAxis < 0) { vel.x = -walkSpeed; transform.localScale = new Vector2(-1, 1); } else if (xAxis > 0) { vel.x = walkSpeed; transform.localScale = new Vector2(1, 1); } else { vel.x = 0; } if (isGrounded && !isAttacking) { if (xAxis != 0) { ChangeAnimationState(PLAYER_RUN); } else { ChangeAnimationState(PLAYER_IDLE); } }
Any help would be massively appreciated thank you!