Skip to content

Instantly share code, notes, and snippets.

Created October 27, 2013 13:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Blender script to make an object follow points on a curve
import bpy
import mathutils
C = bpy.context
def insertKeyFrames(obj, curve):
points =[0].points
duration =
N = len(points)
framesPerPoint = duration / (N-1)
for pIndex in range(0, N):
frameNumber = int(framesPerPoint * pIndex)
pointLocation = points[pIndex].co[0:3]
absPointLocation = curve.location + mathutils.Vector(pointLocation)
obj.location = absPointLocation
obj.keyframe_insert(data_path="location", frame=frameNumber)
selected = C.selected_objects
curve = next(x for x in selected if x.type == 'CURVE')
nonCurve = (x for x in selected if x.type != 'CURVE')
for obj in nonCurve:
insertKeyFrames(obj, curve)
except StopIteration:
print("You need to select one curve")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment