How to anchor an Node2D when scaling?

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

I’m scripting a duck/crouch action to a platform-ish game, and I wanted to implement it downscaling the hitbox (an CollisionShape2D node), preferably tweening the scale. The thing is: when I tween/change the “CollisionShape2D:shape:extents” property, the scaling happen uniformly from both sides, and the desired behavior would be for the bottom of the shape to remain in the same place while the top smoothly shrinks downwards.
I guess what I’m really looking for is: how can I change the scaling anchor/pivot from a Node2D (more specifically a CollisionObject2D) node via code? Is there some other simpler way to do this that I’m missing?

before anything else, thank you for the attention. :3

Good question, I also ran into this issue for my crouch state. I currently just keyframe both the size of the CollisionShape2D and its position directly into my animations.

Diet Estus | 2018-10-22 23:51

My current workaround has been to move the hitbox into the ground, but that could be an issue if you had thin platforms on your game. I tried experimenting with moving and resizing but I couldn’t get it nicely synced when using non-linear interpolations ;-;

llkcbr | 2018-10-23 01:37

:bust_in_silhouette: Reply From: TheGreatButtby

You might find better luck having two hit boxes that switch on or off depending on the state that your character is in but another way to do it with just script would to shrink the extent and move the position down.