Preventing movement during animations

Al Heck
2 min readMay 25, 2022

We currently have an issue — we can move while kicking. How do we prevent this? We need to create a bool on the FPC and then do return functions to know when they turn on and off.

We don’t want to be able to kick unless we are grounded. Let’s add that check in our kick function.

Create a _canKick private bool. Next, in our move field, we want to add the bool to grounded. Create a function that changes the kicking bool when called from our custom controls.

In the movement area, let’s put an if check to see if you are not kicking, you can keep moving.

In your custom controls, grab your first person controller.

When you start kicking, we want to tell our FPC that we are kicking and pass in a bool. When we are done, let’s set it back to false using the animator state. This is done with a coroutine.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ