How to force an object to stay inside a trigger collider?.

Title says all, I need to be able to force a game-object to stay within the boundaries of a set of colliders, it must be able to exit one trigger collider and enter another one if they are overlapping, but not to ever be outside the boundaries of a trigger.

How should I go about this?, an if statement checking if it’s still inside the a trigger, and then pushing it back if it isn’t, would that work?, it needs to be subtle enough that it won’t jitter when it tries to escape the boundaries, and simply act as if there were a wall there.

You could surround the object with non-trigger Colliders when it enters the trigger object. If you have an overlapping trigger then you would not create a boundary collider for that section where the triggers intersect.

Another approach would be to have code that checks for when the object tries to exit the Trigger volunme (OnTriggerExit) and then force the object’s position back to where it was in the previous FixedUpdate, back inside the trigger. In this case to allow the objects to pass to the next trigger you would have a check in the OnTriggerExit to see if the object has entered the other trigger (which should happen as they overlap, right?).

I would recommend the first method as it’s simpler.