How to make this Colldier setup?

Hello everone!
So I made an illustrtaion to show what I want to achieve.


So basically I want circles (green ones) that have a smaller collider(small red one) in them that stops them from leaving an edge collider(the red edge collider). While there is a green edge colldier as well that can collide with the larger green circles. The large green circles can also collide with them selves.

I tried just parenting the smaller circles to the larger ones but they doesnSt seem to work even if I remove the rigidboy 2D from the cricles it still just slides trough the collider. (The collider in the gif suppose to represent the red innder edge collider.) (The small white circles that you can see in the gif are the inner smaller circles they got outside becasue they had a dynamic rigidbody on them. After I removed the rigidbody it still didn’t work)
Could someone please help me with this?

Using physics this way is going to be difficult, as the number of objects in jostling contact will be high. Usually to get satisfactory results you would have to crank up the various iteration settings in the physics engine, which can take a lot of CPU time to get satisfactory simulation.

Also, be sure the ONLY way you move physics items is by calling .MovePosition() on the Rigidbody. Any other way bypasses the physics system (eg, don’t call transform.Translate() and don’t set transform.position directly).

Alright, thanks! I mean I did the collision stuff on collision layers. It’s weird it’s so hard.
I guessed that most stuff ignores physics. I used MovePoistion with the drag feature, but it probably refreshes too often to not clip into it.

You should do all physics-related moving only in FixedUpdate(), which will keep you in sync with the physics engine.

For more info about this, here is some timing diagram help:

https://docs.unity3d.com/Manual/ExecutionOrder.html

The only exception is actually gathering input such as GetKeyDown() or GetMouseButtonDown(): those MUST be read in Update() or you will miss clicks. Then act on the input later in FixedUpdate(), such as for jumping based on a key/button down. See their docs.

1 Like

Thank you! The .MovePosition function worked very well. Now most things act as they actually should.

1 Like