Support Forum

2D Physics Capsule Collider and 2D Collision Testing

Hi there, love the product.

I have a 2D game that fakes a partial side / isometric perspective. As such, all of my sprites need to have capsuleCollider2D objects at their base (especially the larger sprites, which are quite a bit wider than they are high). These capsules don’t rotate, but 2D physics mode in Astar only has circle and point options (no capsule).

My workaround to get the sprites to not get stuck against walls & obstacles is to use collision testing and a circle size that is the larger of the two capsule dimensions, but given that my capsules are about 2:1 aspect ratio most of the time, this really unnecessarily restricts my player and ai movement options (I have to design levels with really wide hallways, else they think they won’t fit when their capsule collider easily does).

Is there a feature here that I’m missing? I looked through the forums & docs and didn’t find anything relevant to my use case, and in fact saw a post where it was said that “capsule collider doesn’t make sense in 2D” but I didn’t understand why. Thank you!

Forgot to mention, I’m using the Pro version at the latest ## 4.2.15 (2020-03-30)

I would really really like to be able to make this work, but I still haven’t been able to find any sort of workaround to not having capsule shape for collision testing.

Hi

Yes that’s unfortunately not suported at the moment. What you would need to do is to modify the code to add an additional 2D physics mode. The reason the regular capsule mode is not supported in 2D is because the regular capsule has its height direction along the up axis, and in 2D that axis does not exist, so it just projects down to a circle.

You can find the relevant code in the Base.cs script inside the method called Check.

Thank you so much for this! I will give it a try, and if I manage to extend it in a functional way I’ll post the code here for others.

1 Like