I’m trying to make several ‘bugs’ (small gameObjects) move around eratically on the surface of a cube, but I can’t quite seem to wrap my mind around the best way to do it 
The bug is constantly affected by a local gravity the makes sure the bug stays on the cube. When the bug reaches the edge I want it to move over the edge, maintaining its current dirction, but getting a new local gravity corresponding to the new face of the cube.
So far I’ve been trying to solve it with OnTriggerExit. When the bug exits the cube trigger and moves over the edge, the bug will get a new local gravity based on it’s local position compared to the cube. I’m moving the bug using translate, and I’m having problems with giving it the right rotation when it get’s a new local gravity.
I’m thinking there must be a somewhat simple way to solve this problem that just keeps escaping me. Any ideas?
What method are you using for calculating the local gravity? I would simply compare the magnitude of the x, y z components of the bugs relative position, with the greatest of those indicating which face the bug is on. As this is a fairly simple method I would call this every frame and continuously check which face the bug is on, rather than trying to detect when it leaves a face. If this is what your stuck on I can post some code outlining how that would work.
If that’s not the problem, what specifically is. You mention having trouble with getting the right rotation - do you mean simply having the bug’s vertical aligned with it’s new local gravity, or maintaining its heading when it goes over an edge? If it’s the latter you may be able to create a rotation quaternion using Quaternion.AngleAxis() with the edge your crossing as the axis, and then apply that to the bug’s rotation to flip it around the edge without losing it’s heading. If you provide a little more detail on the problem your having, preferably with the code your trying to use now, I may be able to provide a more useful answer.
Couldn’t you just store the position of the bugs as 2D x/y between 0.0 and 1.0 and a face#, then update that XY position and have a function that will translate that coordinate to world space coordinates (kinda like UV mapping) onto the face of the cube. Have a couple of simple checks to detect when it moves off a face (if x > 1.0…) and change it’s face# and coordinates ect.
No need to use gravity or triggers as you’ll be mapping it’s location directly to the face of the cube. For rotations, just store the previous local space x/y and use it to derive a heading. You’ll need to set fake previous x/y’s as you change faces, but keeping it all in a 2D local coordinate space should make that much simpler and easier to understand.
There is a handy component called Constant Force, to which you can feed your vectors instead of applying them through script every frame. Maybe that will help make things a little simpler.
(Component) Unity - Manual: Constant Force component reference
(Script definitions) Unity - Scripting API: ConstantForce