Creating a curved, moveable collision shape from code.

Godot Version

4.6

Question

I’m trying to solve what I thought would be a simple problem but is turning out to be much harder than I thought. To summarize it succinctly, I want to make a ring in 2D with a ball inside, and the ring can be spun and the ball rolls around inside.

However I don’t want to use a sprite to create this ring shape. I would like to essentially generate the collision shape from code and _draw the graphics. The reason for this is so that users can create custom levels.

It seems the collision objects creation in godot isn’t really equipped to accomplish my goal unless someone here has a good idea about how to approach this problem.

You can do it by adding points to a polygon shape used with CollisionPolygon2D node.

3 Likes