Rolling ball rig?

Hello there!
I’ve been trying to make an automatic rolling ball rig, but to no prevail. I want it to rotate automatically when I move it on the x and y axis, but the ways I can think of (constraints, drivers, and I even tried the animation nodes addon), use the rotation style specified. I noticed that euler rotation is the best, but only if I move the ball on the x and then y, or vice versa under different orders.

do you guys know of a way to overcome this problem? my latest idea was to get the local rotation and do some node magic with the animation nodes addon, but there is no way to get the local axis :frowning:

If the movement is on a flat plane, this is just simple math in the drivers.

Play along:
Add one driver for the X Euler angle, we will copy it for the Y angle after.

(Because this is just academic…)
Start with the Y position of the sphere (Name the var yloc).
then get the sphere’s dimension property (Name the var sdia).
Now in the calc property of the expression: yloc * (sdia * 0.5).

!!!
!!! If its rolling the wrong way: yloc * (sdia * 0.5) * -1 !!!
!!!

Now copy this driver to the Y angle, and change the yloc to xloc, and update your formula to match.

If you are not on a flat plane, this will take some imagination to get correct.

Hope this helps!

If you want any more understanding to why this works, let me know.

OK, I played, and I see your problem now…
Sorry it took a little playing to actually see it.

My best guess is:
to get a ratio between the distances on the X & Y axis, and then use sin and cos functions to resolve the hypotenuse angle.

This actually works, until you roll over any axis by 180°.

See the attached, it should get you a little closer, now probably just need to add a function to detect if:
180 <= roll < 360 and use that result to require the appended -1 on the formula or not.

ballDriver.blend (498 KB)

OK, from what I can gather from the docs, Euler has an apparent problem that get compounded, once you get past 90°.

Axis angle seems like it would do the trick theoretically, if you were to treat the W axis as the total roll angle
(distance from origin * sphere radius), Leave Z = 0.000, and then use the X/Y as ratios of each other that when added together = 1.

I hope that makes sense.

When I get a chance, I will try to prove it out, unless you can beat me to it.
Hope you get there. This is an interesting problem.

OK, thinking about this one some more, I’ve been approaching this one all wrong.

When I was thinking angles, I was thinking how to arrive at a certain location in space on a 2D plane (eg. traditional Trig).

The problem on a sphere, is that you need to understand it’s direction of travel, meaning you would need to update its origin.
The easiest way that I could think of in blender, would be to use two empties.
everytime the ball changes direction, you would have to move both empties to the same location (less 0.00001 - Otherwise you would get some strange momentary wigging out) in the last direction of travel.

One empty would be an origin target, the other would follow (Track To Constraint) the centroid of the sphere.
Then you could track back to the origin target, effectively giving you the local direction of the sphere.

This causes a slightly different problem to be worked out.
But you could use the Z Rotation of the Tracking Center Empty, and you could use the Local X-Axis of the Centroid empty for the roll amount.
If you could then combine the two and copy the rotation values via the Constraints (because you have the options there for local/transform/world outputs), you technically should be able to get the correct roll effect.

The tricky part would be to update the origin empty, and the Centroids X-Roll Angle (Based on current Angle plus change in distance again).

I think this will really depend on your context.
Game, animation, etc…

if it is animation, you would probably be wise to add a driver function to do this on frame change.

Anyway after mulling it over in my mind, this seems like the most reasonable approach.

Please let me know if you do anything with it.
Good Luck!

Hey, I saw this problem and I think I found a solution. It only works in one of the grids (top right in overhead view:,


but maybe your (sdia * 0.5) * -1 !!! will fix it???

The ball blend file:

Ive been trying to do that for years!

Do you know how to fix it so the ball will roll correctly on both sides?

so, I just discovered that you can write a full script and use it as a driver, so I’ll try that with wikiwiggs’s suggestion, though I don’t fully get it, and I’m not that experienced in scripting :stuck_out_tongue:
and I’m doing this for an animation, not a game engine

Since this is for animation only, I’m wondering if the better approach would be to animate the material map from the node editor???
It seems to me that this would have less of the same problems the 3D Geometry would have within Blender’s Different Rotation Modes.

Of course it would greatly depend on the geometry (If there are any holes or what not, but for a solid sphere why not), probably worth a shot.

that wouldn’t work though, because there are seams

I was thinking about using quaternions, and I figured the only way to do it is to make a driver script, but I don’t know much about scripting, so I was waiting for school to start because I know a guy who might be able to help me with that XD
thanks for that. That is precisely what I was looking for!