Skip to content

Instantly share code, notes, and snippets.

@Fintan
Created February 2, 2019 22:22
Show Gist options
  • Select an option

  • Save Fintan/56bf5617568c054410bb2b0b685254cb to your computer and use it in GitHub Desktop.

Select an option

Save Fintan/56bf5617568c054410bb2b0b685254cb to your computer and use it in GitHub Desktop.
add tracking camera at cursor in Blender
import bpy
cursorLoc = bpy.context.scene.cursor_location
# create camera at cursor
cam = bpy.data.cameras.new("Camera")
cam_ob = bpy.data.objects.new("Camera", cam)
cam_ob.location = cursorLoc
# add to default collection
col = bpy.data.collections['Collection']
col.objects.link(cam_ob)
# track camera to default cube
trackCube = cam_ob.constraints.new("TRACK_TO")
trackCube.track_axis = "TRACK_NEGATIVE_Z"
trackCube.up_axis = "UP_Y"
trackCube.target = bpy.data.objects['Cube']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment