Forbid player to move while attack is launched

RaeJjin0

Member
Hello guys

I would like to setup my character in a way that the player could actually attack while in movement, But then, when the character is attacking, the player could Not move again until the attack animation ends. (the character will then move only thanks to the animations root motion, the player couldn't use the WASD nor joystick to move him until the attack animation ends).

i've already tried to setup the animator in a way that all movements (walk/run etc...) animations only operate when the "Slot0ItemStateIndex is Not Equal to 2", without success, the character gets completely and undefinitely stuck when i try to move while attacking (probably because i haven't found a solution to only cancel the movement Until the animation ends :p)

Thanks in advance, and sorry for your time !
 
Well i think the correct way would be to sort out your Animator and animations to remove movement (simplest sounds to have dedicated static attack animations, triggered by their own IDs, since this will remove the oddness of a character standing idle with nearly no leg movement whilst swinging a potentially heavy weapon), but this is a little hard to comment on (for testing consider a mixamo attack animation with no root motion).

A hack would be to have a Use state on the CharacterLocomotion that sets motor rotation multiplier and position motor multipliers to 0. The animations will of course still play, but you will freeze the player movement and rotation because of the lack of motor (note there are different setting for root motion and non root motion in the controller and i cannot recall what they are called, but they can be set in a state preset).
 
Last edited:
@DankP3 is spot on. A simple way to accomplish this is to create a state which disables Allow Positional Input on the Use ability. Alternatively if you use root motion the solution would be to just remove the root motion from the attack animation.
 
Thank you, it works like a charm this is amazing ! I just had in addition to completely remove the "Move = true/false" condition on transitions from Any State to the combo animations, this works great.

I have another question concerning the attacks. Actually, the system always remember in which attack number the character was. To be more clear, when i attack twice, the system will remember it and then if i decide to press the attack button again 10 minutes later, it will trigger the third attack animation instead of going back to the first one. How can i setup everything so that there is a hidden timer of like 2 seconds, which when the player doesn't keep attacking it resets the combo ?
 
Top