Choose dynamic curve

Hi all!

How can I make my object follow random curve (from 1 to 3)?

So basically choose one curve to follow, and stick with it (not change curves)?

local bezier = require('bezier') local object= display.newImage("images/object.png") object.x = \_W/2 object.y = \_H - 250 object.name = "object" local curve1 = bezier:curve({150, 1100, 150},{ 1080, 686, 500}) local x1, y1 = curve1(10.51) local line1 = display.newLine(x1, y1, x1+1, y1+1) line1:setStrokeColor(0, 0, 1, 1) line1.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve1(i) line1:append(x, y) print(i, x, y) end local curve2 = bezier:curve({150, 1100, 150},{ 500, 200, 300}) local x2, y2 = curve2(10.51) local line2 = display.newLine(x2, y2, x2+1, y2+1) line2:setStrokeColor(0, 1, 0, 1) line2.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve2(i) line2:append(x, y) print(i, x, y) end local curve3 = bezier:curve({200, 900, 100},{ 1080, 686, 500}) local x3, y3 = curve3(10.51) local line3 = display.newLine(x3, y3, x3+1, y3+1) line3:setStrokeColor(1, 0, 1, 1) line3.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve3(i) line3:append(x, y) print(i, x, y) end -- move object along curve local pointInc = 0.00 local function follow\_curve (event ) if pointInc \< 1.01 then object.x,&nbsp;object.y = curve1(pointInc) -- print(pointInc,object.x, object.y) pointInc = pointInc + 0.01 else Runtime:removeEventListener("enterFrame",follow\_curve) end end Runtime:addEventListener("enterFrame",follow\_curve);

In above code I follow curve No. 1, but how to follow random curve?

I tryed to conctatenate “curve” … x (where x is a math.random(1, 3)) but this does not work…

Tnx.

Gogi

Googling curved path following corona sdk blog brings up:

https://coronalabs.com/blog/2014/09/09/tutorial-working-with-curved-paths/

 and other related links:

https://coronalabs.com/blog/2014/01/07/tutorial-moving-objects-along-a-path/

Remember,the blog here has a wealth of articles with lots of useful nuggets.

Hi roaminggamer, thank you!

But these links are not exactly what I was aiming at.

I am aiming at how to dynamically choose function (in this case a curve - which is a table I assume)?

So basically, simple concatenation to call a function/variable/table (if that is possible).

Apologies, but curved paths are a bit of an advanced and usage specific topic.  Also, I didn’t have the time to try to grok your original code and question.  

Also, you’ve assumed we all have access to the ‘bezier.lua’ file you’re using.

You’d be better off packing up your whole project and sharing it as a zip file so others can pull it apart.  Or, better yet, make a small project with just the path code above and dependencies.  Either way, I would need more context to puzzle this out based on your original question.

Googling curved path following corona sdk blog brings up:

https://coronalabs.com/blog/2014/09/09/tutorial-working-with-curved-paths/

 and other related links:

https://coronalabs.com/blog/2014/01/07/tutorial-moving-objects-along-a-path/

Remember,the blog here has a wealth of articles with lots of useful nuggets.

Hi roaminggamer, thank you!

But these links are not exactly what I was aiming at.

I am aiming at how to dynamically choose function (in this case a curve - which is a table I assume)?

So basically, simple concatenation to call a function/variable/table (if that is possible).

Apologies, but curved paths are a bit of an advanced and usage specific topic.  Also, I didn’t have the time to try to grok your original code and question.  

Also, you’ve assumed we all have access to the ‘bezier.lua’ file you’re using.

You’d be better off packing up your whole project and sharing it as a zip file so others can pull it apart.  Or, better yet, make a small project with just the path code above and dependencies.  Either way, I would need more context to puzzle this out based on your original question.