2
$\begingroup$

I have a script that creates a closed curve, and I now want to have a camera which moves along the curve and looks slightly ahead on the curve. The camera moves, but it doesn't stay on the curve itself. (I also haven't tried to tackle the looking ahead).

import bpy

points = [((-10.875,-0.444,0.122),(-16.375,5.056,0.122),(-5.375,-5.944,0.122)),
          ((11.125,-0.444,0.122),(4.420,-9.648,0.122),(17.602,8.447,0.122)),
          ((22.125,10.556,0.122),(9.216,6.553,8.612),(31.022,13.315,-5.729)),
          ((-0.284,16.306,0.122),(-25.732,16.306,-49.859),(25.164,16.306,50.103))]

curveData = bpy.data.curves.new('path', type='CURVE')
curveData.dimensions = '3D'
curveData.resolution_u = 2

polyline = curveData.splines.new('BEZIER')
polyline.bezier_points.add(len(points)-1)
polyline.use_cyclic_u = True
for i, ((x,y,z), (lh_x, lh_y, lh_z), (rh_x, rh_y, rh_z)) in enumerate(points):
    polyline.bezier_points[i].co = (x, y, z)
    polyline.bezier_points[i].handle_left = (lh_x, lh_y, lh_z,)
    polyline.bezier_points[i].handle_right = (rh_x, rh_y, rh_z)

curveOB = bpy.data.objects.new('path', curveData)

scn = bpy.context.scene
scn.objects.link(curveOB)
scn.objects.active = curveOB
curveOB.select = True

cam = bpy.data.cameras.new("Cam")
cam_ob = bpy.data.objects.new("Cam", cam)
bpy.context.scene.objects.link(cam_ob)

cam_ob.location = points[0][0]

cam_ob.select = True
bpy.ops.object.parent_set(type='FOLLOW')
$\endgroup$
1
$\begingroup$

The camera is following the curve, it is just offset right now so the behaviour looks odd.

You need to set your camera to the starting point of the curve. Which is the point (-0.284,16.306,0.122).

| improve this answer | |
$\endgroup$

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.