Notifications
Clear all

[Closed] Movement along spline

Hi!
I have the following problem. I have an object and I have a spline. How can I move my object along the spline per script? It is a closed spline (ellipse) and I want to say for example that the object should take 20 steps to the origin point where it starts, or 40 steps and so on. With steps I mean frames. How can I do this? And I also want to repeat the movement about 100 times.
Respectfully,
cgneuling

5 Replies
 PEN

Curious why a path constraint will not work?

my object follows the path. That’s no problem but how can I set the velocity of the object?

and with speed I mean that I want that for example the spline is circled in 100 frames

1 Reply
(@johnwhile)
Joined: 11 months ago

Posts: 0

like this ?

fn get =
(
	delete objects
	pathspline = convertToSplineShape (ellipse length:100 width:200)
	obj = convertToMesh (box length:10 width:10 height:10)
	
	PathConstraint= path_constraint()
	PathConstraint.path = pathspline
	obj.position.controller = PathConstraint

	if pathspline.numsplines != 1 do (print "i want a simple spline" ; return 0)
	
	perimeter = 0.0
	for seglength in getSegLengths pathspline 1 cum:false do perimeter+= seglength
	
	velocityframe = 10.0 -- 10 unit's length per frames
	timeframe =  perimeter /velocityframe
	timeframe as integer
)
timeframe = get() as time

or something like this:


fn pathConstaintLoop node path loopTime:100 =
(
	c = node.position.controller = path_constraint path:path axis:2 constantVel:on follow:on
	p = c.percent.controller
	
	enableORTs p on
	setBeforeORT p #cycle
	setAfterORT p #cycle

	deletekeys p #allkeys
	k = addnewkey p 0
	k.value = 0
	k = addnewkey p loopTime
	k.value = 100
)
(
	delete objects
	animationrange = interval 0 1000
	
	path = ellipse name:"Path" length:100 width:200 wirecolor:green
	node = box name:"Node" length:10 width:10 height:10 wirecolor:yellow
	
	pathConstaintLoop node path loopTime:100
)