Notifications
Clear all

[Closed] path percent based on original position

Hi,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?

4 Replies

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

 -- add path constraint
 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: %
" 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

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

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

Thanks Martin, i totally overlooked shape methods


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