How do I add a camera and script it so that it moves along a path while focusing on one object? I would also like to know how to have it rotating around the origin where one of the main objects of interest sits.

  • 1
    $\begingroup$ Hundreds of options, I think this is the way to go... $\endgroup$
    – brockmann
    Mar 5 '20 at 15:46
  • $\begingroup$ HI. Are you specifically wanting to do this as a script or did you just mention that because you think it's a possible solution? $\endgroup$ Mar 5 '20 at 16:11
  • $\begingroup$ Yes specifically as a script. But thank you for the link anyway! $\endgroup$
    – Jenny
    Mar 5 '20 at 16:29

Basic example using a circle based on Cegaton's setup from here.

enter image description here

Add the primitives and a camera. Assign each object reference to a new variable and add a Follow Path and Track To constraint using Object.constraints.new() method. Finally set all the constraint properties, eg. assign the variables to the FollowPath.target or set TrackTo.up_axis to 'UP_Y':

import bpy

# Add Suzanne
suzanne = bpy.context.object

# Add Circle
circle = bpy.context.object

# Add Camera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object

# Follow Path Constraint
fp_constraint = camera.constraints.new('FOLLOW_PATH')
fp_constraint.target = circle

# Animate Button
    'constraint':camera.constraints["Follow Path"]
    }, constraint='Follow Path')

# Track-To Constraint
tt_constraint = camera.constraints.new('TRACK_TO')
tt_constraint.target = suzanne
tt_constraint.up_axis = 'UP_Y'
tt_constraint.track_axis = 'TRACK_NEGATIVE_Z'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.