This is actually way more difficult and time consuming than I imagined, especially considering that the colliders can also be convex objects, and not just spheres or cubes.
So I started studying collisions, which is the basis for any physics engine.
Instead of implementing everything with simple colliders, I decided to go directly to the algorithm for convex colliders, which is the GJK.
It is quite complex, especially in 3D, but it has a great advantage: it can check collisions between any kind of shape that can answer to the question: "Which is the farthest point I have in the given direction?"
So It is possible to check collisions between a mesh and an ellipse curve for example.
Also, for convex meshes, it is faster than the SAT method.
In the picture I implemented it in just two dimension, and I used sphere colliders.
In the picture I implemented it in just two dimension, and I used sphere colliders.
The three external spheres check collisions with the central one, and the left one is yellow because it is not colliding.
Tomorrow I'll add AABB colliders as well, and i'll try to make them collide between each other.
Extending the algorithm to 3D is pretty annoying and error prone, I expect it to be hard, I'll try to do it soon

Nessun commento:
Posta un commento