Stop movement during animation help

I have my project set up so I can walk, run, jump and kick with my animations, but i want to force stop the movement during the kick/attack animation. Here’s my code:

{
//input fields
private RPGActionsAsset playerActionsAsset;
private InputAction move;

//movement fields
private Rigidbody rb;
[SerializeField]
private float movementForce = 1f;
[SerializeField]
private float jumpForce = 5f;
[SerializeField]
private float maxSpeed = 5f;
private Vector3 forceDirection = Vector3.zero;

[SerializeField]
private Camera playerCamera;
private Animator animator;

private void Awake()
{
    rb = this.GetComponent<Rigidbody>();
    playerActionsAsset = new RPGActionsAsset();
    animator = this.GetComponent<Animator>();
}

private void OnEnable()
{
    playerActionsAsset.Player.Jump.started += DoJump;
    playerActionsAsset.Player.Attack.started += DoAttack;
    move = playerActionsAsset.Player.Move;
    playerActionsAsset.Player.Enable();

}

private void OnDisable()
{
    playerActionsAsset.Player.Jump.started -= DoJump;
    playerActionsAsset.Player.Attack.started -= DoAttack;
    playerActionsAsset.Player.Disable();
}

private void FixedUpdate()
{
    forceDirection += move.ReadValue<Vector2>().x * movementForce * GetCameraRight(playerCamera) * movementForce;
    forceDirection += move.ReadValue<Vector2>().y * movementForce * GetCameraForward(playerCamera) * movementForce;

    rb.AddForce(forceDirection, ForceMode.Impulse);
    forceDirection = Vector3.zero;

    if (rb.velocity.y < 0f)
        rb.velocity += Vector3.down * Physics.gravity.y * Time.fixedDeltaTime;

    Vector3 horizontalVelocity = rb.velocity;
    horizontalVelocity.y = 0;
    if (horizontalVelocity.sqrMagnitude > maxSpeed * maxSpeed)
        rb.velocity = horizontalVelocity.normalized * maxSpeed + Vector3.up * rb.velocity.y;

    LookAt();
}

private void LookAt()
{
    Vector3 direction = rb.velocity;
    direction.y = 0f;

    if (move.ReadValue<Vector2>().sqrMagnitude > 0.1f && direction.sqrMagnitude > 0.1f)
        this.rb.rotation = Quaternion.LookRotation(direction, Vector3.up);
    else
        rb.angularVelocity = Vector3.zero;
}

private Vector3 GetCameraRight(Camera playerCamera)
{
    Vector3 right = playerCamera.transform.right;
    right.y = 0;
    return right.normalized;
}

private Vector3 GetCameraForward(Camera playerCamera)
{
    Vector3 forward = playerCamera.transform.forward;
    forward.y = 0;
    return forward.normalized;
}

private void DoJump(InputAction.CallbackContext obj)
{
    if (IsGrounded())
    {
        forceDirection += Vector3.up * jumpForce;
    }
}

private bool IsGrounded()
{
    Ray ray = new Ray(this.transform.position + Vector3.up * 0.25f, Vector3.down);
    if (Physics.Raycast(ray, out RaycastHit hit, 0.3f))
        return true;
    else
        return false;

}

private void DoAttack(InputAction.CallbackContext obj)
{
    animator.SetTrigger("attack");
}

}


If anyone can help me with this I’d appreciate it a lot

Okay well what you should do is create a function called StopWalking() and StartWalking() in that script.

void StartWalking()
{
 walkspeed = 0;
}

void StopWalking()
{
walkspeed = defaultspeed;
}

Next, on your kick animation, create 2 animation events. One at the beginning of the kick, and one at the end. Adding the StopWalking() function to the first event, and the StartWalking() to the last event.
——————————————————————-——————————
This should work for any animations you want to stop the movement for, although I don’t recommend ever stopping the players movement. Hope I was able to help!

https://forum.unity.com/threads/stopping-an-animation-on-a-specific-frame.692260/