Changing collision shapes

I’m using my own game art assets as I’m following the course so that I end up with my own customized platformer by the end.

For the different animations within AnimatedSprite, the sprites I’m using change shape and orientation quite dramatically from state to state (i.e. idle vs run vs jump vs hurt vs dead) .

My question: is it possible to change the extents and position of CollisionShape2D to match the sprite animation states? I’m not doing any fancy shapes, just rectangles or capsules would suit my purpose.

So far I’ve puzzled out the following:

$CollisionShape2D.get_shape().set_extents(Vector2(x, y))

This (I think) can change the dimensions on the fly depending on the motion function being called [e.g. func run()]. However, I’m not sure how to manipulate the Node2D position property for the CollisionShape2D.


Have you tried using the AnimationPlayer on the collision object?

Here are some things I found on the net:

1 Like

Privacy & Terms