View Full Version : Wheel Rotation Script

09 September 2006, 02:36 PM
Basically the script creates a Circle that you should change the Radius of to match the size of your real wheel and however much you adjust the radius or the actual path it should still rotate properly

Before you run the script you MUST create a nurbs curve as a path for the wheel to move along

more info here on my site (

Download the script (

If theres any problems please let me know - and suggestions to clean it up etc. are very welcome as its basiclly just some actions recorded and then the main wire parameter added in.


09 September 2006, 04:04 PM
Hi Simon,

That's a cool script, very helpful. I was just this morning working out an expression for this on a vehicle i was making. Its a shame i didn't see this script until i finished!

It has got me thinking though - I have made a script that takes a curve and moves a dummy along it according to a certain distance every 8 frames. The reason is we have loads of characters with pre-animated (i.e. on the spot) walk cycles and sometimes we need to walk them in to/out of shot etc and my script allows us to link the character to this for exact walk animation along curves with minimum footslip.

I calculate the path percentage vs curvelength for each character's walk distance, and work out the maximum numer of steps they can take down the current path.

It then animates it every 8 frames (or whatever the walk cycle duration is) until it reaches the end. Ive added a few more things like custom starts, stops and a 'visual' linear walk approximation too.

I wondered if it was possible to do something similar to what you have done that has the dummy on the path and calculates on the fly too via an expression, so if you altered the spline's shape the dummy would still walk the same distance according to the characters walk cycle duration. It would be a kind of rig that you could tweak to get the correct position for the character as the dummy animation wouldn't need to be re-calculated after changing the shape.

What do you think? :)

09 September 2006, 11:06 AM
Sounds like you should be able to do it

I calculate the path percentage vs curvelength for each character's walk distance, and work out the maximum numer of steps they can take down the current path.

do you mean you work this part out seperately and use the answer in the script somewhere? If you want it to be able to change relative to the curvelength etc you just have that working out in the script couldn't you? ... Not sure, can't quite get me head around what you're asking at the moment :)

09 September 2006, 12:12 PM
Hi simon,

Sorry if im not making too much sense.

yes it is worked out separately when you pick the spline with a certain character selected. If the character travels, say 10 units on each cycle, and it is an 8 frame cycle, you can work out the maximum number of steps along that spline, as well as how long it takes. What i thought would be nice is rather than (as my script does) apply a path constraint to a characters movement dummy and then animate along the picked path (converting the walk distance array of the character into path constraint percentages every 8 frames) i could somehow use an expression controller to do this on the fly, so if you wanted to tweak the path position afterwards you could without having to re-run the calculation.

09 September 2006, 03:06 AM
You should make it a fn, so people dont need to rename there stuff plus if dummy01 exists in the scene there screwed. Also using nurbs splines is not good for big scenes - dont know if max has fixed the messages bug.

struct wheelroll

fn wheelpath path wheel =

p = point() = (uniquename + ( as string + "_point" ))
p.pos = [0,0,0]

wheelTemp = circle radius:20 pos:[0,0,0] name: (uniquename + as string)
rotate WheelTemp (angleaxis -90 [0,1,0])

wheelTemp.parent = p

p.pos.controller = position_list()
p.pos.controller.avaliable.controller = path_constraint()
p.pos.controller.path_constraint.controller.appendTarget path

p.pos.controller.path_constraint.controller.follow = on
p.pos.controller.Path_Constraint.controller.constantVel = off

rotate wheeltemp (angleaxis 90 [0,0,1])

p.pos.controller.Path_Constraint.controller.percent.controller = bezier_float ()
paramWire.connect p.pos.controller.Path_Constraint.controller[#Percent] wheelTemp.rotation.controller[#Y_Rotation] "(Percent)*(((curveLength $" + as string + " )/(2*PI*$" + WheelTemp as string + ".radius))*360)/(360/(2*PI))"



now call the struct to make it an instance:

wheelroll_c = wheelroll()

Then wheelroll_c.wheelPath $curve01 $wheel01

Something like that anyway - havent tested it. I love structs!

edit cant remember if you have to add "\"" to the being of the wireparam, to encapsulate the quotes.

09 September 2006, 09:57 PM
Hi Charles,

I too have just started to use data structures and i'm finding the ability to access scene aspects in a more organised way very interesting. I hadn't thought about placing a function inside a struct and it is a really nice way of accessing it. I guess If you had a longer script you could group similar functions into a struct this way, and help with the organisation of things.
Although i use functions a lot, i sometimes find they are all bundled in the start of the script in no particular order and it makes navigating more dificult. This way you could have a separate struct for each type of function set and call it in the way that you have detailed. Thanks a lot.

09 September 2006, 10:20 PM
Bingo, thats exactly what i do. I have a struct with a ton of fns inside it, i can call it in additional scripts, you can even can fns with fn in a struct:

struct test

fn test1 a b = ( return (a+b)),
fn test2 c =( return (test.test1 + c))
struct instancing is very powerful, because variables inside, become unique - you dont need globals, which arent that good to use. Virtually any container in max can hold virtually anything. Ive used CA blocks to hold fns, that variables outside in script controllers access. Fns can be embedded virtually anywhere in a scene and outside too. And most of my scripts are just fns calls returning vals going into more fns.

09 September 2006, 10:23 PM
great stuff Charles, very interesting. Thanks for your input.

CGTalk Moderation
09 September 2006, 10:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.