How to get the collider to follow the animation? (2D sprite)

Hello, i’m currently in the process of learning unity and c#. And in this process, up until now. I’ve just used oversized colliders to cover the whole animation. But now i’m trying to get the colliders to follow the animation. I managed to do this with a circlecollider on my attack-animation. Now i’m trying to make a collider for when i’m walking. I’ve searched around, and i haven’t been able to get it right, any advice would be helpful.

I’ve tried this answer:

But with no luck. All my colliders just end up stacking on top of eachother, even when it’s not in the animation where i’ve added the events. Resulting in a floating sprite not affected by the gravity of rigidbody.
(I want colliders, not triggers as it’s the character and i obviously want it to be able to collide.)

Thanks for any advice! :slight_smile:

Can’t you simply animate the collider properties using a new curve in the animation window? (Not near a computer to test but can’t see why you wouldn’t be able to animate collider size/position just like any other transform property)

I found a solution to this after spending some more time researching the issue. I copied a code from this thread! (CGshady’s code)

https://forum.unity3d.com/threads/is-it-better-to-use-sprite-swapping-or-animations.271278/#post-1793895