Bending an 2D animated sprite & its hitbox

Godot Version

4.5.1 stable

Question

Hello!
I have the following animated sprite, imagine its tail swinging left and right, and possibly biting when needed. This is done through a sprite2D + AnimationPlayer combination and a state tree.

I would like for the shark to be able to

  1. Bend its “spine” when turning toward something, while continuing its animation (see the following screen).
  2. The hitbox to be able to match the transformed sprite.

I would like your input on how to achieve that.

Note: I would like to have this framework for different creatures, and thus the hitboxes might be a bit less simple/rectangular. the transform will always be the same.

So far

I have had limited success on bending the sprite while playing ONE animation, the swimming one. I did so by switching to a polygon2D + Skeleton2D and using an animatedSprite2D as texture for the polygon2D, but:

  1. I can’t see a way to make that support multiple animations
  2. I also failed to use the resulting transformed sprite to modify the hitbox on the go - i assume this data is calculated thanks to the polygon + bones transforms on the GPU and never leaves it. (i tried the .uv, and .polygon of the Polygon2D, they don’t update)

You probably don’t need the collision shape to be that accurate, give your player some leniency and use boxy or capsule shapes.

You could use two separate collision shape nodes and rotate one at the same pivot point as your animation, you’ll have to keep them aligned and that can be tough work.

That’s a good point. Due to how i use hitboxes for my homemade lighting system i’d rather have 1 hitbox polygon per entity. I suppose i can calculate the position of each of its vertex based on the bone they are perpendicular to, though. That should not be an enormous issue?

That still solves only part of the problem though, as the current solution i have does not support multiple animations and is (very) burdensome to setup (clicking each polygon vertex to setup the internal polygons is horrendous). I’d love to hear input on how to handle more animations and hopefully a bit more streamlined!