Skip to content

Instantly share code, notes, and snippets.

@roymath-zz
Last active April 19, 2020 02:24
Show Gist options
  • Save roymath-zz/96bdde4b35effa1aed074d27d30de450 to your computer and use it in GitHub Desktop.
Save roymath-zz/96bdde4b35effa1aed074d27d30de450 to your computer and use it in GitHub Desktop.
"""
This is a code version of the rig animation technique shown by `blenderBinge` in
https://www.youtube.com/watch?v=K02hlKyoWNI - consider it a thankyou for teaching
us how to.
"""
import bpy
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_monkey_add(size=2, enter_editmode=False, location=(0, 0, 0))
bpy.ops.curve.primitive_bezier_circle_add(radius=6, enter_editmode=False, location=(0, 0, 0))
bpy.ops.object.camera_add(enter_editmode=False, align='VIEW', location=(0, 0, 0), rotation=(0, 0, 0))
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(-.3, -.3, -.3))
bpy.context.active_object.name = 'Empty2'
monkey = bpy.context.scene.objects['Suzanne']
circle = bpy.context.scene.objects['BezierCircle']
camera = bpy.context.scene.objects['Camera']
empty = bpy.context.scene.objects['Empty']
empty2 = bpy.context.scene.objects['Empty2']
camera.parent = empty
constraint = empty.constraints.new('FOLLOW_PATH')
constraint.use_curve_follow = True
constraint.use_fixed_location = True
constraint.target = circle
constraint = camera.constraints.new('TRACK_TO')
constraint.show_expanded = False
# constraint.mute = True
constraint.target = empty2
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_Y'
scene = bpy.context.scene
scene.frame_start = 1
scene.frame_end = 25
# animate the rig
constraint = empty.constraints["Follow Path"]
for f, o in [
(1, 0),
(10, 0.3),
(20, 1),
]:
constraint.offset_factor = o
constraint.keyframe_insert(data_path='offset_factor', frame=f)
# animate the empty near Suzanne
empty2.keyframe_insert(data_path='location', frame=1)
empty2.location = (0, 0, -1.5)
empty2.keyframe_insert(data_path='location', frame=18)
camera.location = (0, 0, 2)
camera.keyframe_insert(data_path='location', frame=2)
camera.location = (0, 0, -1.5)
camera.keyframe_insert(data_path='location', frame=18)
# show at 5fps
bpy.context.scene.render.fps = 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment