I bet you're wondering how exactly I managed to solve a problem, only to find out I hadn't. The answer, ironically, is that due to my own relief at having found a solution, I failed to test it properly to ensure it works in all scenarios. Allow me to demonstrate.
Thanks to the VTC online training centre tutorial on the Expression Editor within Maya, I learned that it is possible to, for lack of a better phrase, 'make something happen when something else happens'. The example in the video was to make a ball automatically roll when a box is moved. Since I would need the box to be invisible in my animation, to try this all for myself I substituted the box for a locator. Everything worked perfectly with the following expression:
Simple! Basically, this is set up so that the golf ball rotates about its Z axis, when the locator is moved in the X direction. At this point however, the tutorial ends, giving no further insight other than 'if you want the ball to roll in another direction, use another expression'. Easy enough to comprehend, so I proceeded to add the following expression:
Did it work? Of course not! When moved in the X direction, the ball rolls as you would want, but it seems impossible to get it to roll in the Z direction. So I thought about this for some time, until I eventually realised that the expressions are with relation to the object's local axis and not the global axis. Whilst at university, I experimented with rotating the locator/ball combination (the two were parented) and was relieved to find that the ball turned and rolled in a different direction accordingly! In the following playblast video, watch the brown ball closely to see what I mean:
Cue hours of feeling delighted that I had found a solution. It wasn't until I got home and tried to use this in my animation that I realised my mistake. Case in question, the blue 'planet Earth' ball in the video above. Notice how it stops rolling as soon as it begins to move purely in the Z direction? It's the same problem as before. The brown ball never actually moves purely in the Z axis since it is moving diagonally. Because of this, even though it is technically moving in the Z direction and rolling, you realise that at the same time it is moving an equal amount in the X direction- and it is this movement causing it to roll!
Back to square one (or square two, depending on whether you see the revelation of failure as a step in the right direction overall), I devised a new solution; If the locator's movement in the X direction is what controls the ball's rotation, if I could move the two independently (move the locator in the X direction an equal amount that the ball rolls in the Z), perhaps the ball could be turned 90 degrees so that it rolls the correct way? Alas, it seems that the ball only rolls when it and the locator are parented before being key-framed- which means they can't be separated.
Out of other options, I have decided to manually animate the ball instead. As you can see in the next video, I have set up a basic scene to practice. By setting a key frame at the beginning, and another at the end with the ball rotated several times, the animation plays such that the ball rolls smoothly- and just look at what direction it is rolling in!
Unfortunately, manually animating the ball will take longer if I want the rotations to be accurate, since to determine the amount of times the ball needs to roll across the mat I will have to calculate its circumference. It's a good thing I know that a golf ball is 1.68" in diameter!
The reason I have taken the time to voice my confusion on this matter is because there seems to be no logical way to truly solve the problem. If anyone knows a way to do so, please leave a comment below! So much for the Expression Editor in Maya- through all of this, the only correct expression is one on my face: Sad.