- Home /
Stop Movement while attacking
I need to be able to stop my character from moving when ever it plays an attack animation. Can anyone offer a solution.
function Attack(){
//Play the animation, set attacking true for 1 second and then back to false
animation.Play("attack");
attacking = true;
yield WaitForSeconds(1);
attacking = false;
}
Answer by Bravini · Nov 14, 2010 at 11:07 PM
if the movement code is in the same script, just nest it into an
if(!attacking){//your movement code here }
otherwise set the attacking as
static var attacking: boolean;
then the previoslu mentioned if would be
if(!scriptname.attacking){//your movement code here }
you can see an example of this on the First Person Shooter example of unity on the Walker script they use a isGrounded var to check if the character is on the ground before jumping.
Answer by J0hn4n · Jul 17, 2017 at 01:29 AM
Hello i know its a old post but i find more usefull use a FSM to movement logic, this avoid a bunch of if else statements.
Your answer
![](https://koobas.hobune.stream/wayback/20220613083040im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Play animation for horizontal and vertical movement? 1 Answer
How to use 'check if player is on ground' bool in script 2 Answers
Mixing Unity Mecanim and Scripted Bones/States 1 Answer
How to trigger animations in a script using character controller ? 0 Answers