How to add rigid body to non convex mess collider object in 2d?

Hi
I have been working on unity project for Android Platform. The goal is: User draws various shapes with touch. Once the user removes touch, the drawn shape should fall to the ground.

In my code, line renderer is used to draw shape. Once touch phase ends, the drawn shape is baked into mesh and mesh collider is attached to the object. Then rigid body is attached to the object.

Problem: It shows an error message: “Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5”

I tried with edge collider 2d. But the problem with edge collider 2d, the shapes that has edge collider are not colliding with each other.

Please guide me to overcome the situation. Thanks.

What is a mess collider?

What about adding a BoxCollider2D?

It is a hand drawn shape. Thats why I am going for mesh collider.Box collider 2d is not the solution because it would cover up the entire drawn shape. I want collider in the drawn shape only.

Nothing.

Did you try BoxCollider2D anyway? You can resize it to your needs.

Hi APSchmidt. Thanks for your response.

Please look at the image. This is a c shape. User draws this shape with touch (single touch only) on phone. The red marks is the collider I want on it. Note: The red mark is strictly inside the shape of the c. So far I had succeeded with edge collider 2d. But the problem with edge collider 2d, two different shapes with edge colliders are not colliding with each other. So I have opted mesh collider. With mesh collider, rigid body is not working. I am wondering with box collider 2d, how can I achieve it?

Well, images speak more clearly than words hey? :slight_smile:

I don’t understand how you could add colliders and a rigidbody to an object that doesn’t exist though. How do you detect the player drawing the shape and convert it to a game object?

He he he he he he…

(My apology if explained too much below)

Unity for Android has touch feature. Inside update function, we can check whether user has touched the screen, whether the user has moved the finger on the screen of android phone and whether the user moved away his finger from the screen.

Inside the user moved the finger check block, I captured all the touch positions and stored in a list. And then I have assigned the positions list to line renderer. Line renderer fills the positions list and it appears as if user draw a shape on the screen.

Once the shape is drawn, we can add component rigidbody2d to the created shape. and also if we want to add edge collider then we have to convert list to array (There is function that converts list to array) and then assign it to edge collider 2d. It will occupy entire shape.

Hope you have understand the logic. Sorry for my English.

1 Like

I think I’ve got it. Not bad at all. So, you need to add a collider to the shape but what is the rigidbody for?

To make it fall to the ground. User going to draw multiple shapes. And also These shapes should react if they collide with each other.