Visualize Capsule Collider 2D at runtime for the users

Hi there,
I am developing a 2D ship builder for users. Each ship will have a Capsule Collider 2D component attached, representing the ship’s shield and covering the entire ship. How to visualize this capsule collider for the users?

The size and aspect ratio of this capsule collider 2d will vary depending on the dimensions of the ship. Therefore, simply adding a generic capsule sprite will not be enough.

Found it:
If you only need to visualize the Collider2D without involving any physics, use CreateMesh()
https://docs.unity3d.com/ScriptReference/Collider2D.CreateMesh.html

For other purposes, use GetShapes():
https://docs.unity3d.com/ScriptReference/Collider2D.GetShapes.html

2 Likes