The Spinning Expresion
We'll need a mathematical expression in the wheel's x-rotation controller. In this expression we need to find the x-rotation value regards the distance travelled by the tank. I could give you the expression and you could use it without knowing how it was made, but I wouldn't be a good teacher if I make it so easy!
Seriously speaking, its better that you start understanding how to make expressions for future rigs challenges. So, here we go, a small and very easy mathematical lesson:
How can we find the wheel's x-rotation? Think about the distance that a circumference needs to travel to make a full turn. This distance is equal to its perimeter (2*pi*radius).
To find the numbers of turns along a distance, we could take this distance and divide it by the distance travelled by one turn (as mentioned before, one turn is equal to the perimeter). For example, if we have a distance of three times the wheel's perimeter, dividing the first value over the perimeter will give us a number of 3 turns.
And what do we do next with the turn's number? We could multiply it by its equivalent in degrees, 360º or 2*pi in radians, and we got our expression!
This expression goes as follows:
(Distance / (2*pi*Radius)) * 2*pi
Actually, we may cancel the (2*pi) values by themselves. 2*pi / 2*pi is equal one (1), so we can remove these numbers, they're irrelevant now.
We got: Distance / Radius.
And what about the distance? How can we find it? We could do it using the percent along path of the path constraint, and the path's length. One value by the other will give us what we wanted: Distance= (Percent/100)*SplineLength, we divide Percent by 100 because here we need a percent that goes from 0 to 1. When the percent is 0% the distance is 0, when the percent is 100% the distance is equal the Spline's Length. 50% will give us a half of the spline's length, and so...
Finally the expression goes as follows: (Percent/100)*SplineLength / Radius
Now, we're going to put this expression in the wheel's x-rotation controller, we'll be using the script controller.
Select the wheel, in the Motion Panel open the Assign Controller rollout, select the Rotation: Euler XYZ Controller and click in the assign controller button, select Rotation List. With a list of rotations we may have 2 controller layers, one for the script and the other one for manual adjustments. Open the rotation List, in the Available controller assign an Euler XYZ controller, this controller is for manual adjustment, so we need to set it to active by double clicking it in the Rotation List rollout, or by clicking the "Set Active Button". When a controller is active this one will be the one that we'll be modifying by the rotation gizmo (manual adjustment).
Go back to the first Euler XYZ controller in the Assign Controller Rollout, open it, and in the x-rotation controller assign a float script controller
In the Expression Text Box write: SplineLength=curveLength Path, this line enables us to get the path's length using the curvelength maxscript function (it doesn't work well if the path spline is scaled). In the next line write the expression, (Percent/100)*SplineLength / Radius.
Then, we have to create the variables, and assign them their respective values.
In the Create Variable Group you have to write the names of the variables exactly as they're written in the Expression text box. Start writing the Path, then click on the Create Button, do the same with the Percent and radius.
We do not need to create the SplineLength variable because it going to get its value inside the script.
If we evaluate the expression now, we're going to get nothing, because we need to assign the variables to their respective values.
- Select Path in the Variables List and click in the Assign Node button, select the "Path" spline object in the "Track view Pick" DialogBox.
- Select Percent in the Variables List and click in the Assign Track button, select the control_Main's path constraint percent controller.
- Select radius in the Variables List and click in the Assign Constant button, write 0.473 (you can find it using the tape helper object measuring the wheel's diameter and then dividing by two).
You could assign the wheel's radius parameter to the radius variable if you need to change the wheels radius in the future.
If you evaluate now, we get our auto spinning system! You can check it out by moving the control_main object.