+1 vote

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

in Engine by (21 points)

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.

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 ;-;

1 Answer

0 votes
Best answer

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.

by (58 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.