Hi everyone, first post (that I remember of anyways), long time lurker.
I’m an industry professional trying to get started in Unity and so far I’m having a lot of problems with how physics work. I hope someone can give me some answers and explanations.
I am using the 2d framework, and I’m trying to create a 2D character controller, with a square collider. The problem is that the physics seem to allow interpenetration to happen all the time. If my character simply walks on the ground and jumps around, he never lands at the exact same height. On some occasions, the character falls a bit too far and gets stuck there. I saw 2 solutions being offered on various threads.
1- Boost the physics timestep. In my opinion this is not a valid solution as it only reduces the chance of seeing that issue occur. a stable solution should work no matter what your performances are. I don’t mind my game being a bit more jaggy and less precise if the physics frame count is lower, but it should not allow my character to become stuck.
2- Use raycasts. While this is a bit better, I still do not understand why this should be needed. Ideally I expect my engine to push any colliding elements away from one another until they no longer intersect. Why does unity allow things to interpenetrate in the first place? Is there a way to do such a thing? When a collision occurs, check the contact normals, push them away following that normal, check if they still collide and so on, in a single frame (aka not waiting for the next fixed update to figure if you pushed them far enough). I know there is a script around that prevents that, but it simply nullifies an object movement if said movement would make it penetrate something else. I’d want the movement to still occur, but be shortened to get to the edge of said collision.
I did try to implement raycasts, but a couple of issues still occur. for example, if i jump on a higher platform and I hit the corner of said platform with the character’s feet, I can get stuck. I also believe that performances would quickly degrade if I had for example 50 enemies on screen, each raycasting the ground to avoid getting stuck.
So I guess my question is, why does the engine allow interpenetration, and is it possible to force any object colliding with another, to stand edge to edge with the other one, instead of being inside it?
Thank you all for your help, and please refrain from giving workarounds such as “use a capsule collider” or “don’t use unity” ![]()