Unity 2d Collider help

Hi, I’m trying to make the player bounce inside a hand drawn circle-shape that has space in the middle, does anyone know how to add collider to a handdrawn shape? thanks

I want the player (green ball) to bounce inside the brown circle, but I can’t figure out which/how the collider works for handdrawn shapes

When you say “handdrawn”, do you mean it is just a sprite that you made in some other program?

If you want to define a collider with arbitrary shape, you can look into Edge Collider 2D. You will have to define the edge points manually.

Generally colliders have an interior and an exterior. This means you can’t just use a CircleCollider2D and move around “inside” of it.

To collide with the interior of the circle you probably want to make two half-circle colliders for each half of the circle.

If you need example code to turn geometry into colliders, see the testfingerpolygons scene in my MakeGeo repository.

Relevant polygon generation code:

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

1 Like

thanks, I looked online and was suggested a polygon collider which also seems to do the trick

1 Like

You should be able to use a PolygonCollider2D as you mentioned but I would select the Delaunay option on it.

Also note that in later versions of Unity you can use a CompositeCollider2D to perform operations such as carving out areas. You can create the above ring with two CircleCollider2D with the larger one being the outer radius and the smaller one being the inner radius subtracting from it. This can give you a lot more control over the end result and won’t have any extra runtime overhead if you’re not changing it at runtime.

3 Likes