1
$\begingroup$

I've got a tube, created from a bezier curve, similar to this example. I'd like to be able to move an object along this curve, as if it were a spline, in Unity. From Unity, I need access to each point in world space, so that I can adjust the object that moves along it programmatically (Animation will not work).

Is there a nice way to turn the various points along that curve into objects that I can then get the position of inside Unity, or do I have to manually add objects?

Thanks in advance for any hlep!

$\endgroup$
  • $\begingroup$ You could convert a curve to mesh and add particle system. Adjusting settings, you can get desired objects e.g. at the locations where vertices of the curve are placed. I'm not sure these cubes really can describe all the needed points of the curve though. $\endgroup$ – Mr Zak Sep 8 '15 at 17:43
  • $\begingroup$ What about a script that created an Empty where each point on the curve is? Would that work for what you need? You can hook the Empty's to the points as well to control their position if needed. $\endgroup$ – Todd McIntosh Sep 8 '15 at 18:13
  • $\begingroup$ @ToddMcIntosh That would be perfect. Any idea how I go about accessing these points in order to use them in a script? $\endgroup$ – nathansizemore Sep 8 '15 at 18:15
1
$\begingroup$

Would it be practical to use the formula for a Bezier Curve (wikipedia article)?

B(t) = (1-t)**3*P0 + 3*(1-t)**2*t*P1 + 3*(1-t)*t**2*P2 + t**3*P3

You can evaluate it for t varying from 0..1. One complication is that the distance between evaluated points will vary, so if you want constant speed you'll have to compensate by adjusting your time->t mapping. P0..P3 correspond to the points and handles of each segment of the bezier curve.

Here is a short python example of how to inspect the control points and handles of a bezier curve (in case you are unable to inspect them in the N-panel pop-out of the 3D view):

import bpy

def mission1(curve):
    for spline in curve.splines:
        for kp in spline.bezier_points:
            print("%r"%[kp.handle_left, kp.co, kp.handle_right])
        print("")

mission1(bpy.context.active_object.data)

See also Mathematical formula for Bezier curves and How can I know the data paths of certain point of bezier curve?

$\endgroup$
  • $\begingroup$ That would be great, but I still need a way to get the points from the curve before I can do any math to interpolate the vertices myself. $\endgroup$ – nathansizemore Sep 8 '15 at 18:14
  • $\begingroup$ I have upgraded my answer with sample python. $\endgroup$ – Mutant Bob Sep 8 '15 at 18:23
0
$\begingroup$

I've found an alternative to the accepted answer:

If you create a path/curve, then create an empty object, vertex, and parent that object to the path/curve, after selecting the empty object again and going de-selecting Speed under the frames, it will duplicate itself across the path. At that point, there will be a new empty object along each section of the path and it will import into Unity the same way.

$\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.