Blender script to make an object follow points on a curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import mathutils | |
C = bpy.context | |
def insertKeyFrames(obj, curve): | |
points = curve.data.splines[0].points | |
duration = curve.data.path_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 | |
try: | |
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