Im planning to create a 2D rockstack game, a main function is the game will generate random shape of rocks. theres two way and neither of them doing well.
- use mesh create polygon: I follow the instruction here https://www.youtube.com/watch?v=YG-gIX_OvSE, but I dont know how to add collider and rigibody for the object.
- Use 2d sprite shape, but I have no idea how to control the shape or vertex or generate it by code.
Any suggestion will be helpful, Thank you
1 Answer
1
Heyyo!
For the two ways presented, here’s how I’d approach each one of them:
-
- To add those components to the mesh you’ve generated (assuming you have a variable named obj as your GameObject that has the mesh you want to add these components to), use PolygonCollider2D PolygonCollider = obj.AddComponent(); //You can change the “points” property to match with your generated mesh to have the collider shape match with your mesh shape
And
Rigidbody2D Rigidbody = obj.AddComponent();
Or if we are strictly following the tutorial you linked, you could manually add the mesh colliders and the rigid body components, and then change/assign them through code to your meshes/objects after.
-
- 2D Sprite Shapes seems like a method that requires more hand authoring. Might not be great for the use case if the goal is to generate the rocks procedurally.
Hope this helps! Let me know if there’s anything unclear or could be elaborated more on ;D