I want to have a 2d physics object hold other objects and move around, keeping them contained. Both have rigidbodies, the box has 3 box2d shapes on its sprite…
I’ve tried moving the box with transform.position, rigidbody.moveposition etc, if i move slowly the circle are still contained but as soon as i move a little fast they pass through like this…
The only reason the balls are moving upwards is because you are causing them to overlap the bottom of the object (bad) and the physics system solves the overlap which is always the shortest distance out of the overlap. If the ball is slightly below the center point of the base then it’ll solve it by moving the ball below it.
So never create overlaps if you can avoid doing so.
If you move the Transform then it immediately moves the object to that position; it doesn’t cover the distance inbetween i.e. it teleports it from one position to another. This can cause colliders to be overlapped.
If you move the ‘container’ using Rigidbody2D.MovePosition then it will work but if you intend to move it fast (as was mentioned above) use continuous collision detection in the Rigidbody2D. MovePosition moves the body to the specified position during the next fixed-update and will calculate collisions from the current position to the new one you specify which will include collisions with the balls. All it really does is calculate the velocity required to move to the new position in a single fixed-update so it’s effectively moving as normal i.e. through space. This doesn’t affect the bodies inherent velocity which is still maintained.
Also, you need to set the ‘container’ to be a Kinematic Rigidbody2D body-type if you don’t want the balls to affect (push back on) the ‘container’ itself.
You should not need to change the fixed time step for any of this to work.