3dsMax script controllers are enormously powerful tools for creating custom character rigs. This tutorial will show you how to make a very simple eye rig in 3dsMax and introduce script controllers to make an animator GUI.
Setting up the scene
Get the sample files
Download the sample files from my site. Open the ‘Eye Start.max’ file.
Make the Control object for the eye
- In the front Viewport from the ‘shapes’ creation panel make a Rectangle, Length 90, width 110, Corner Radius 0.
- Again in the front viewport from the ‘Shapes’ creation panel make a Circle, Radius 20. Align it to the centre of the rectangle, and then Link it to the rectangle.
Assign the script controllers to the eye.
- Select the ‘Eye L’ object. Go to the ‘Motions’ Panel and in the ‘Assign Controller’ rollout expand the ‘Rotation: Euler XYZ’ part of the controller tree.
- Click on the ‘X Rotation: Bezier Float’ entry. The click the ‘Assign Controller’ button from the list pick ‘float script’ then click ‘OK’.
- The ‘Script Controller: Eye L\ X Rotation’ window should pop up.
- In the ‘Create Variable’ edit text box type ‘Angle’ (without quotes) then click the create ‘Create’ Button.
- ‘Angle’ is now added to the list of variables. Select it from the list then click the ‘Assign Track’ Button at the bottom of the screen.
- Navigate to ‘Circle01’ position controller and pick ‘Y Position: Bezier Float’ from the list then click Ok. At the bottom of the script controller panel you should now see ‘Assigned to: Target: $Circle01.pos.controller.’Y Position’ ‘
Writing the maxScript expression
Up and Down
- Now we are ready to write our script. In the Expression window change the text to the word Angle (complex wasn’t it!). Now click the Evaluate button.
- The Circles Y position now controls the up/down rotation of the eye. Try moving the circle up and down.
- Ok so at the moment the control is not very useful. Even small movements of the circle seem to make the eye spin round and around. This is because the script controller needs an angle in radians. 180 degrees = pi radians. I.e. 1 degree = 0.0175 radians. So were going to need to modify our script a bit. So go back to the expression window and change ‘Angle’ to ‘Angle * 0.0175’. Click ‘Evaluate’ and move the circle up and down to see what happens’
- The control has a much more useful range. You can adjust the scale of the control by adjusting the size of the number’
Left and right – How to set an offset
- Add a script controller to the Z Rotation of the eye.
- Notice that when the ‘Script Control’ window pops up the expression window reads -3.14159 ie the eye is initially rotated by -pi radians or -180 degrees.
- create the variable ‘Angle’ and Assign it to ‘Circle01’ ‘X Position’ track.
- In the expression window change the text to ‘Angle * 0.0175’, then click ‘Evaluate’
- The eye flips round to face the opposite way. This is because we need to offset the initial angle of rotation.
- Go back to the expression window and change ‘Angle * 0.0175’ to ‘( Angle + 180 ) * 0.0175’. Click ‘Evaluate’ and move the circle left and right to see what happens’
- The eye is facing the right direction. Later we’ll change the offset value to move the eyes focus point.
Adding Limits using If … do …
A Limit controller could be used to stop the eyes rotating too far. However for the purpose of this tutorial we are going to use an if … do … statement
- Select ‘Eye L’ then Right Click on ‘X Rotation:Float Script’ in the assign controller tree. Select ‘Properties’ from the list and the ‘Script Control’ window pops up.
- Create a new variable called ‘Limit’ and assign to the track ‘Rectangle01’ ‘Object(Rectangle)’ ‘Length’
- Replace the text in the Expression window with the following.
Max = Limit * 0.5 if Angle > Max do Angle = Max if Angle < -Max do Angle = -Max Angle * 0.0175
- Edit the ‘Z Rotation:Float Script’ Create a new variable called ‘Limit’ and this time assign to the track ‘Rectangle01’ ‘Object(Rectangle)’ ‘Width’
- Replace the text in the Expression window with the following.
Max = Limit * 0.5 if Angle > Max do Angle = Max if Angle < -Max do Angle = -Max ( Angle + 180 ) * 0.0175
Adding the ‘Point of focus’ Control
- Go to the ‘Create Panel’. Pick ‘Helpers’ ‘Manipulators’ ‘Slider’. Add a slider manipulator to the top right of the front viewport.
- With the slider still selected in the ‘modifier panel’ change ‘Minimum’ to -20 and ‘Maximum’ to 20.
- Select ‘Eye L’. Edit the ‘Z Rotation:Float Script’ Create a new variable called ‘Focus’ and this time assign to the track ‘Slider01’ ‘Object(Slider)’ ‘Value’.
- Replace the text in the Expression window with the following.
Max = Limit * 0.5 if Angle > Max do Angle = Max if Angle < -Max do Angle = -Max ( Angle + 180 + Focus) * 0.0175
- In the top menu bar check on the ‘Select and Manipulate mode’ button.
- If you adjust the slider you will see the eye move left and right.
- Copy the ‘Eye L’ object move it to [-90,0,0] and rename it ‘Eye R’
- Edit the ‘Z Rotation:Float Script’ for ‘Eye R’. Change the last line of the expression text to ‘( Angle + 180 – Focus) * 0.0175’. The Script should now read.
Max = Limit * 0.5 if Angle > Max do Angle = Max if Angle < -Max do Angle = -Max ( Angle + 180 - Focus) * 0.0175
- Now when you adjust the slider the eyes cross…
What it all means
Max = Limit * 0.5
We want to limit the eyes rotation to an angle in degrees based on the size of the rectangle. If the length of the rectangle is 90 we want to limit the eye rotation to 45 degrees up and 45 degrees down.
if Angle > Max do Angle = Max
This the ‘If…do..’ statement i.e. ‘If (something is true) do (something)’ In this case it means. If the ‘Angle’ is greater than the ‘Max’ angle then make ‘Angle’ equal to ‘Max’.
if Angle < -Max do Angle = -Max
This makes sure that the angle is never less than the minimum.
( Angle + 180 + Focus) * 0.0175
The final value in the script is the one used by the eye rotation.
Here all the angles are added together in degrees and turned in radians by multiplying by 0.0175 ‘Angle’ is generated by the movement of the circle ‘focus’ is generated by the slider ‘180’ is the offset. ie. rotates the eye to point it in direction when the circle is in the center of the rectangle.
Modifying the script
Scaling the controls.
Max = 45 angle = angle * 2 * Max / limit if Angle > Max do Angle = Max if Angle < -Max do Angle = -Max ( Angle + 180 - Focus) * 0.0175
Here the eye rotation is limited to +45 and -45 degrees (the ‘Max’ variable) and the circle position is scaled to match the edges of the rectangle. i.e. you can change the size of the rectangle to change the size of circle movement needed to rotate the eye.