Need help with the physics and angles of gerbils in a plastic ball..

Ok, so I know that’s an odd question, but the problem is simple.

I have an inverted sphere, with an object inside it, resting at the very bottom. So if the sphere is at 0,0,0 and the radius is 100, then the object is resting at 0,-100,0. Think of this “object” as a Gerbil, or a Hamster.

Now, here’s where I’m having trouble with the math.

If the Gerbil moves along the “ground” (along the xz plane), I want the sphere to move with him. Now that would be as easy as setting the position of the sphere, relative to the Gerbil. But I also want the sphere to have rotated by the appropriate amount in 3d space.

So rather than try to move the sphere, I want to rotate it in such a way that the gerbil is always on the bottom.

I’m having trouble figuring out the math to calculate the delta angle on the edge of the sphere, based on the delta position that the Gerbil has moved.

Any ideas?

EDIT: To clarify - I need the sphere to be anchored at 0,0,0 - and the hamster’s movement just rotates the sphere. Hamster controls the sphere, the sphere does not control the hamster.

If I was doing this, here’s how I’d approach it:


In 2d, as your gerbil moves forward, he’s running on the edge of a circle, which is an arc of the circle. Given the arc and the radius, you can find the angle pretty easily.

In 3D, there is always some 2D circle in the same plane as the gerbil (if you think about the gerbil as a flat plane; but the same thing should work if you just consider the gerbil’s midline). So then it’s a matter of finding two things: first, the angle the circle traveled and second, the axis that that circle is centered on relative to the sphere.

The first part is easy, uses the same math from above.
The second part is more interesting/complex. It seems to me that there’s some rotation around the vertical axis that will describe the circle, since the gerbil is always on the ground. So I’d figure out what that is, (probably by getting angle between gerbil.right and ball.right or something like that), then do the math to figure out how far the ball needs to move in that direction. Rotate the ball by the first angle, around the vertical axis, then rotate by the second angle around the right axis.

Maybe. Who knows.

So I solved this by letting Unity do the work. Basically, I created a separate “Simulator sphere” with a rigidbody, and placed it elsewhere in the world, on a massively large plane.

Then, I place the camera at the bottom of the large “world” sphere. Then, I look at the Input.GetAxis to see which way the player is moving. I then AddForce to the “simulator sphere”, and it rolls according to the forces.

I then set the rotation of the world sphere to be equal to the rotation of the “Simulator sphere”. So it effectively feels like you’re controlling the ball that you’re inside of, and works perfectly as expected, even though the world sphere never moves, it just rotates.

You feel like you’re walking around this “hollow earth” world, but really, it’s just rotating to match what a sphere elsewhere in space is doing in response to your key presses. Works quite nicely.