Activity › Forums › Adobe After Effects Expressions › Animating A Bicycle With Expressions
-
Animating A Bicycle With Expressions
Posted by Charlotte Caetano on March 5, 2009 at 10:56 pmHi there,
I’m quite new to expressions and really only understand the very basics.
I am however, trying to create 2D bicycle which moves realisticly.
I have found that Carl Larsen’s “The Vehicle Rig” expression is perfect for the bike wheels to rotate when ‘pushed’
I have also found that a partial expression from Alex Dinnin’s “Rotating Wheels” post very helpful in order to enable rotation speed to be varied depending on how many revolutions the “Pedal Wheel” part does.
However I am unable to combine the two expressions on the wheels rotation property. Only one or the other expressions works at any one time.
Also I then wish, if possible, to add a chain with realistic movement that is driven by the “pedal wheels” rotation…
I had thought also that when the bike is being ridden by a character that I would parent the characters foot to the pedal as opposed to having the character actually ‘ride’ the bike as it might be too complex?
Apologies for the long post,
Any pointers or tips to clarify even a little bit of my querie would be great…
Thanks in advance,
Charlotte
Shane Sutton replied 13 years, 7 months ago 4 Members · 8 Replies -
8 Replies
-
Filip Vandueren
March 6, 2009 at 1:39 amYou should frst indeed use the script from vehicle rig to let the wheels turn as the bike moves.
The rear cogwheel will turn as fast as the wheel (it is part of the wheel), so just pickwhip the rotation from the wheel.The front wheel would be the same unless it has a different size.
The front cogwheel with the pedals would turn at a ratio of the back wheel, equivalent to the difference in the number of teeth each cogwheel has. Roughly equivalent to the difference in diameter.
Do yourself a big favour and look up some actual diameters of bycicle cogwheels and teeth-counts. Just picking some numbers at random may give strange and inaccurate results
pickwhip the rotation from the rearcigwheel and multiply by the ratio you calculated.
The pedals are probably parented to the rotating cogwheel, but they shouldn’t rotate along, so give them an expression:
value-parent.rotation;
The Movement of the legs should be done with an inverse kinematics script, so the feet would move (parented to the pedals) the hips stay almost staionary and the movement and rotation of the knees is calculated by the script.
This is no problem. Dan has a great script for this. (check out motionscript.com, or do a search here for inverse kinematics or IK)But I think the most difficult part is a realistic chain. Do you mean by realistic only the motion should be scientifically correct, and can this be achieved with a dotted line (not to hard, using a shape layer with a dashed stroke, and an expression for dash ofset).
Or do you want semi-photorealistic look. In which case the chain should be build from a few dozen layers, one for each chainlink, and a much harder expression I think. -
Charlotte Caetano
March 7, 2009 at 10:09 amHi Filip,
Thank you for your response I shall give it a go.
I had hoped for the chain movement to look realistic -the bicycle and its parts are loosely hand drawn.
Thanks again for your help,
Charlotte
-
Filip Vandueren
March 7, 2009 at 5:30 pmIf the dotted or dashed line look works for you, then check this out:
create two star shape layers, and change the settings around till it looks like a cogwheel:
I started out with 24 and 18 pointed stars, with radii of about 50 and 40 px.
Mucked around with inner and outer radius, some roundness tweaking and this is what I got:

You can also add a second star shape with extreme roundness settings, combine them with ‘”Merge Paths” to get something like this:

The next few steps are the most fiddly: position the cogwheels where you need them, then add a new shape layer by drawing a path that represents the chain, give it a narrow dark stroke:

Call that layer “ChainPath”
Duplicate that layer and rename to “Chainlinks”.
INcrease the stroke width, Add a Dash and a Gap to the stroke, Set The Line Cap to Round Cap.
Now set the Gap to a very high value like 2000. You should see 1 ‘chain link’
Adjust Dash Offset and Dash length till it looks like it fits nicely around 1 tooth of the cogwheel:

Now set the Gap to 0 and start increasing untill every chain fits onto the teeth of your first cogwheel. You might have to tweak the dash length also if it was too long.
The second thing too look out for is that at the end of the loop the links line up, so you don’t have a gap that’s too large, or a link that’s too short or long, as I said, this is fiddly and needs some tweaking, perhaps even lengthening the path of the chain byt moving the cogwheels a few pixels apart, and adjusting the two chain paths to match:

OK, now we need to know the diamter of the circular part of the chainpath on the left side, the radius of that half circle will be somewhere between the inner and outer radius of the cogwheel, you can draw a temporary circle shape on top to find out: draw, and then check the shape contents for it’s size, mine turned out to be 106 px

We need this for an expression in the Dash Offset of the chainlinks:
r=thisComp.layer("large cog 24 teeth").transform.rotation;
circ=Math.PI*106;value + ((r/360)*circ);
Give the small Cogwheel’s rotation this expression:
value + thisComp.layer("large cog 24 teeth").transform.rotation*(24/18)
The large cogwheel has 24 teeth, the small one 18, hence (24/18).
Now rotate the small wheel untill it’s teeth line up with the chainlinks (maybe they already did, but that would be a coincidence).Set a keyframe for the large cogwheel at 0° and 360° a few seconds later.
The Two cogwheels should rotate and the chain should follow. If the chain is completely out of sync, then the radius was not correct, measure again.To fine tune the diameter value:
Go to the 360° keyframe, and jump back immidiately to the 0° keyframe, the chain will probably shift a little, tweaking the value for circ in the dash offset expression via trial and error gave me a more correct value of 106.95, where it lines up perfectly across even a 100 revolutions.Once the expressions worked, I duplicate the Chainlinks twice and by changing the stroke color, the dash/gap settings and offsets, I added little dots that also followed the chain, and made it look a bit more interesting:

and here it is in action:
I hope that’s all clear, it was a fun project to do with shapes, because in theory, the entire thing could be set up within one layer that then only needs to be moved forward and back !
-
Charlotte Caetano
March 10, 2009 at 5:03 pmHey Filip!
Thank you very much for the follow up tutorial and all the effort you put in – it is perfect for the job at hand. I had wondered if it was possible to setup a ‘working’ chain… and clearly it is!
Great Stuff.
Many thanks again for all your help,
Charlotte
-
Filip Vandueren
March 10, 2009 at 11:59 pmglad you saw it.
keep in touch, would love to see your endresult.
-
Shane Sutton
October 4, 2012 at 8:18 pmhi hi
I just found this while looking for something else but it helped me a great deal with another project.
I had a question though. I have all my cogs, chains and wheels on one layer. but I dont know the expression to piont to the path name within my layer. Several paths are on one layer (as your suggestion in this thred – thought id try give it a go).
Is there a simple script for this or am I way off the mark. I’m new to scripting but trying to get a handle on it.My back wheel is driving my wheels. The script for my back cog is:
r=thisComp.Layer(“Back wheel”).transform.rotation; circ=Math.PI*142; value + ((r/360)*circ);The expression will not work as I think it’s pointing to the layer and not the PATH within the layer.
I thought it would work by changing:
r=thiscomp.layer
to: r=thisLayer
but I had no luckAny ideas or did anyone ever get this to work?
Help is greatly appreciated. thanks a mill.
shane. -
Dan Ebberts
October 4, 2012 at 9:06 pmTry using the expression pickwhip to get the correct syntax. For example, the rotation of “Ellipse 1” referenced from another shape on the same layer would be:
content(“Ellipse 1”).transform.rotation
Dan
-
Shane Sutton
October 5, 2012 at 11:39 amahhh yeh,.. should of thought of that.
thanks a mill.
Best
shane.
Reply to this Discussion! Login or Sign Up