How do I have seperate colliders for each animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Aracnido

I am making a 2d metroidvania. And right now I have made the typical movements, fully animated and they work. I also have melee attacks working. Now I have been using the sprite frame animation (not the animation player route) as I was following the tutorial by UmaiPixel and found it very easy. Now I am facing some big problems and I dont know what to do.

  1. I have a sliding mechanic implemented with the animated already in there but how do I change the collider on the player for specific animation i.e the collider is half its height when player is sliding.

  2. I have the attack animations but I want to implement hitboxes for each specific attack, like one attack is a slightly longer ranged than the the other. Again I dont know how to make these hitboxes which are specific to each attack animation and frame.

Any help would be greatly appreciated.

:bust_in_silhouette: Reply From: Dlean Jeans

You can scale your CollisionShape2D:

$CollisionShape2D.scale.x = 1.25 # 25% longer

Note that you can’t scale Circle or Capsule shapes so you gotta use a Rectangle shape. You will probably need to position the shape, too.

What I would do is to save the scale and position of the CollisionShape2D in an AnimationPlayer with animation length of 0 or 0.1, optionally blend between them, then call them like this:

$AnimationPlayer.play('normal_attack')

$AnimationPlayer.play('long_attack')

$AnimationPlayer.play('idle')

$AnimationPlayer.play('dash')