2D kinematic rigidbody collision detection

I’m trying to write a 2d character controller without using dynamic rigidbodies because they need messy workarounds like setting physics materials, disabling gravity, terminating forces, etc.
The best method for doing that i found so far is using kinematic rigidbodies with full kinematic contacts enabled.
Here is the problem: I don’t know how to stop my rigidbody on contact. I can get the contact info but there is no such thing like raycasthit2d.centroid. How do i calculate the place where rb2d should stop?

Rb2D.Cast doesn’t work for me because it can’t have more than one hit point per collider.

If you look at my signature you’ll see a GitHub repository that contains lots of examples of 2D physics features. One miscellaneous example might be useful here as it shows you full kinematic movement. In the example it does stuff like sliding across surfaces which you might not need but it does show you clearly kinematic movement.

KinematicTopDownController

Just download the repo and load-up the scene of the same name as the script above.

Hope it helps.

EDIT: You shouldn’t need to be interested in the centroid, you should be able to use distance of the cast to tell you how far you can move.

1 Like

Yes! Thank you! This is exactly what i wanted to achieve! I found your physics2d example project super useful.