View Full Version : path percent based on original position

 f3derico01 January 2008, 10:31 AMHi,I've a spline to use as path,I place some objects along the spline and then apply a path constraint.obviously percent is 0 and object move it's pos. so now there a way to know the path percent so the objects return to its position?
decon
01 January 2008, 12:57 PM
not sure if i got it right, but comparing positions before and after assigning path constraint should do it. :)

fn goback o l =(
objs = o
ln = l
-- pos before path constraint
posOrig = objs.pos

objs.pos.controller=position_list()
objs.pos.controller.Available.controller = Path_constraint()
objs.pos.controller[2].path=ln
posAfter = objs.pos
frm = objs.pos.controller[2].percent
dOrig = distance posOrig posAfter

for i = 0 to animationRange.end do (
at time i posAfter = objs.pos

d = distance posOrig posAfter

if (d < dOrig) then (
dOrig = d
frm = i
)

)
--format "dis min: % at frame: %\n" dOrig frm
objs.pos.controller[2].percent = frm
deleteKeys objs.pos.controller[2].percent.keys #allKeys
objs.pos.controller.active = objs.pos.controller.count
)

-- usage:
-- goBack \$Teapot01 \$Line01
-- or:
-- for obj in selection do goBack obj \$Line01

f3derico
01 January 2008, 01:21 PM
I've found a little bit dfferent way to solve my problem.

But your script work fine and work for any tipe of spline.
thanks a lot

martinB
01 January 2008, 09:05 AM
FWIW, there is also the nearestPathParam() function that you can call on a spline with a point3 and it will give you the interpolation value between 0...1 of the point on that spline that is closest to the point3.

-- MartinB

decon
01 January 2008, 08:27 AM
Thanks Martin, i totally overlooked shape methods :D

fn goback o l =(
objs = o
ln = l
npp = nearestPathParam ln objs.pos
frm = 100 * (pathToLengthParam ln npp)

objs.pos.controller=position_list()
objs.pos.controller.Available.controller = Path_constraint()
objs.pos.controller[2].path=ln

objs.pos.controller[2].percent = frm
deleteKeys objs.pos.controller[2].percent.keys #allKeys
objs.pos.controller.active = objs.pos.controller.count
)
-- goBack \$Teapot01 \$Line01
-- or:
-- for obj in selection do goBack obj \$Line01

CGTalk Moderation
01 January 2008, 08:27 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1