This is a complex, advanced tutorial showing how to create an animation using Blender's Game Physics Engine and Paths. A Sphere will be dropped onto a Plane, moved along a Path, and then dropped onto a Box.
Blender has the ability to record physics-based actions to an object's IPO. This functionality allows a recorded physics sequence to be rendered as an animation. Since Paths control objects independently of physics, Path motion is not recorded without special intervention. Let us now intervene.
Layout Menu
Blender Layout
Sphere, Box, and Plane
This will align the Path's first vertex with the Sphere's centre. After it falls, the Sphere will move along the Path. There are other ways to align vertices that don't rely on premeditated positioning, like step 18.
Rotating the scene should show a view similar to:
Properly Positioned Path
Material to Cube.
Material to Plane.
The Empty and Path should both be selected.
# # This script is used to map the IPO curve of an object as it travels # through frames of an animation. The algorithm follows: # # 1. Calculate number of steps needed to animate at given framerate. # 2. Get the selected object. # 3. Duplicate the selected object (which will hold the generated IPO). # 4. Reset the duplicate object. # 5. Loop over the number of frames at the calculated framerate. # 6. Set the active frame. # 7. Position the duplicate object to the same place as the selected one. # 8. Copy the selected object's location and rotation into the duplicate's IPO. # # Usage: # (1) Select the object that follows a curve. # (2) Load this script in Blender's Text window. # (3) Move the mouse to the Text window. # (4) Press Alt-p. # import Blender from Blender import Object, Scene framesPerSecond = Scene.GetCurrent().getRenderingContext().fps firstFrame = 0 lastFrame = 100 stepsPerFrame = (lastFrame - firstFrame) / framesPerSecond selected = Object.GetSelected()[0] Object.Duplicate() duplicate = Object.GetSelected()[0] duplicate.clrParent() duplicate.clearIpo() for frame in range( firstFrame, lastFrame, stepsPerFrame ): Blender.Set( 'curframe', frame ) duplicate.setMatrix( selected.getMatrix() ) duplicate.insertIpoKey( Object.LOC ) duplicate.insertIpoKey( Object.ROT )
copy-path.py.
copy-path.py.
While executing, the script instructs Blender to scrub through frames at 25 frames per second (default). With 100 frames, only every fourth frame is used. Each frame that is used causes the duplicate object to have its location and rotation recorded as an IPO key (i.e., a vertex in that object's IPO curve).
Empty.001.
0.
If the Empty moves in unexpected ways, it is likely this step was missed.
Empty's New IPO
180.
This is the number of frames the Sphere takes to hit the Plane.
When the Sphere collides with the Plane the following must happen:
collision.
This will record the Sphere colliding with the Plane. Upon collision, the Sphere must follow the Empty (which has an IPO that was derived from the Path that was banished to layer two).
s.copy.
This sensor will help continually copy the value of the Sphere's
collision property.
s.ipo.
collision.
True.
c.copy.
c.ipo.
a.copy.
collision.
Sphere.
collision.
a.ipo.
100.
The logic should look similar to:
Logic Blocks for the Empty
The logic block instructs Blender to continually copy the Sphere's
collision property into the Empty's property of the same name.
Once the collision property is set to True, the Empty
is instructed to replay its IPO. All that remains is to set the Sphere's
parent to the Empty, remove the parent relationship when appropriate, and
record the Sphere's complete IPO curve.
collision.
time.
A timer will be used to remove the Sphere's parent (the Empty). It is also used to calculate the current frame.
s.plane.
Plane.
s.time.
time.
4.0.
4.1.
s.start.
s.record.
2.
s.stop.
Cube.
c.planec.timec.startc.recordc.stopc.start and c.record.
# # This script is used to record the IPO curve of an object as it is # assaulted by the Game Physics engine. It should be executed automatically # via Logic Blocks. The algorithm follows: # # 1. Get the object being controlled by physics. # 2. Create a new IPO for recording the motion of that object. # 3. Store the IPO curves for use by the frame recorder. # import Blender # Get the name of the object being controlled by physics. # gameObject = GameLogic.getCurrentController().getOwner() objectName = gameObject.getName()[2:] # Create an IPO of type Object named 'Recorded IPO'. # blenderObject = Blender.Object.Get( objectName ) ipo = Blender.Ipo.New( 'Object', 'Recorded IPO' ) blenderObject.setIpo( ipo ) # Get the position of gameObject as IPO curves. # locx = ipo.addCurve( 'LocX' ) locy = ipo.addCurve( 'LocY' ) locz = ipo.addCurve( 'LocZ' ) # Keep a reference to the curves in a global variable. The variable # (GameLogic.rec) is used by a script that records the position of the # game Object per frame. # GameLogic.rec = [gameObject, locx, locy, locz]
record-ipo.py.
record-ipo.py.
# # This script is used to record the position of an object as it travels # through each frame, independent of the Game Physics. If Blender is set # to record Game Physics to IPO, toggle that menu item OFF. This is a # replacement. The algorithm follows: # # 1. Get the object being controlled by physics. # 2. Get the object's position (for a given frame). # 3. Update the recorded curves (stored in the global variable GameLogic.rec). # import Blender from Blender import Scene gameObject = GameLogic.getCurrentController().getOwner() position = gameObject.getPosition() frame = gameObject.time * Scene.GetCurrent().getRenderingContext().fps # Only try to update the curves if the variable has been initialised. # if hasattr( GameLogic, 'rec' ): # Set the curves for the X, Y, and Z axis. # GameLogic.rec[1].addBezier( (frame, position[0]) ) GameLogic.rec[1].update() GameLogic.rec[2].addBezier( (frame, position[1]) ) GameLogic.rec[2].update() GameLogic.rec[3].addBezier( (frame, position[2]) ) GameLogic.rec[3].update()
c.start to
record-ipo.py.
c.record to
record-frame.py.
a.start.parenta.parent.emptya.stop.parenta.parent.nonea.stopcollision.
True.
Empty.
collision.
False.
Logic Blocks for the Sphere
The Sphere should fall from gravity to the Plane, follow the Path, then fall from gravity to the Box.
THE END - Download