I'm working on a 2D game that lets the user move physics enabled objects directly (using the mouse or touches). These GameObjects have colliders and rigidbody attached. For now, we're using boxes, but we plan on having more complex shapes, so we may need to use mesh colliders.
I need to prevent the user from dragging a shape into another one, while still being able to stick them one against the other. I tried using Rigidbody.MovePosition, directly changing the transform position and using AddForce, but all these methods cause varying levels of penetration between objects.
I had excellent results with SweepTest, only moving the object if SweepTest returned false, but SweepTest only works with primitive colliders, NOT with mesh colliders (even when enabling convex mode).
I've considered using MovePosition, then check if the collider fires the OnCollisionEnter callback, and then move back the object if it does, but the callback executes too late, it isn't called as soon as two objects collide, but only at the next FixedUpdate. It could be managed, but would be very cumbersome to work with.
It seems like the only reasonable solution is to combine primitive colliders to form complex shapes, but I'd like to make sure if there isn't another solution, if anyone would like to share it.
It would be great if there was some form of direct collision testing. Something like TestCollision(colliderA, colliderB), that would return true or false, and work with mesh colliders. A bit like SweepTest, but without the sweeping part.
Any pointer is super appreciated, Thanks!