Moving object along predetereming path

Hello Corona community!

I’m seriously stuck on this. I would like to move a circle along a predetermined path that’s a curve. I’ve looked around and I’ve seen some stuff about curves and math.sin, but I don’t know how to implement this! Can someone give me some sample code to get started with moving a circle along a predetermined path like that attached photo?

I’m really struggling with this!

move along path [import]uid: 14218 topic_id: 33198 reply_id: 333198[/import]

Hey,

This would give your object the path you’re looking for.

local trans1 = transition.to(obj, {time = 2000, x = obj.x + 300})  
local trans2 = transition.to(obj, {time = 1000, y = obj.y - 100, transition=easing.outQuad})  
local trans3 = transition.to(obj, {delay = 1000, time = 1000, y = obj.y, transition=easing.inQuad})  

Not sure how well transitions would integrate with the rest of your code but I think the above example works visually.

Hope this helps. [import]uid: 136211 topic_id: 33198 reply_id: 131879[/import]

Carlos Icaza actually posted code to do exactly this; http://www.carlosicaza.com/2011/04/23/moving-an-object-along-a-bezier-curve-part-i/

Peach :slight_smile: [import]uid: 52491 topic_id: 33198 reply_id: 131884[/import]

If you have the points of the path which you want to move along you can also use transitions between each point.

If you want to throw an object along a curve you can also take a look here:

https://developer.anscamobile.com/code/trajectory-plotting [import]uid: 8271 topic_id: 33198 reply_id: 131897[/import]

I used this -

http://developer.coronalabs.com/code/bezier-curve-corona-sdk

Takes a bit of messing about to get the curve how you want but once it’s done, it’s dead easy to get your object to follow it.

In the examples when it does print(i, 'X: ’ … x, 'Y: ’ … y) in a for loop, get rid of the print and set your objects x and y instead.

Dave [import]uid: 117617 topic_id: 33198 reply_id: 131909[/import]

Wow! Thank you for the very quick help. Just out of curiosity, is there a way to do this with physics? Can I apply something like circle:setLinearVelocity to make the circle launch up on a curve and have gravity pull it back down? [import]uid: 14218 topic_id: 33198 reply_id: 131925[/import]

Yes - take a look at the link I sent you, the code does both calculating the trajectory and launching a ball along the same path using the Box2D physics engine built into Corona. [import]uid: 8271 topic_id: 33198 reply_id: 131928[/import]

Very nice, this is what I needed! Thank you!!! [import]uid: 14218 topic_id: 33198 reply_id: 131931[/import]

Hey,

This would give your object the path you’re looking for.

local trans1 = transition.to(obj, {time = 2000, x = obj.x + 300})  
local trans2 = transition.to(obj, {time = 1000, y = obj.y - 100, transition=easing.outQuad})  
local trans3 = transition.to(obj, {delay = 1000, time = 1000, y = obj.y, transition=easing.inQuad})  

Not sure how well transitions would integrate with the rest of your code but I think the above example works visually.

Hope this helps. [import]uid: 136211 topic_id: 33198 reply_id: 131879[/import]

Carlos Icaza actually posted code to do exactly this; http://www.carlosicaza.com/2011/04/23/moving-an-object-along-a-bezier-curve-part-i/

Peach :slight_smile: [import]uid: 52491 topic_id: 33198 reply_id: 131884[/import]

If you have the points of the path which you want to move along you can also use transitions between each point.

If you want to throw an object along a curve you can also take a look here:

https://developer.anscamobile.com/code/trajectory-plotting [import]uid: 8271 topic_id: 33198 reply_id: 131897[/import]

I used this -

http://developer.coronalabs.com/code/bezier-curve-corona-sdk

Takes a bit of messing about to get the curve how you want but once it’s done, it’s dead easy to get your object to follow it.

In the examples when it does print(i, 'X: ’ … x, 'Y: ’ … y) in a for loop, get rid of the print and set your objects x and y instead.

Dave [import]uid: 117617 topic_id: 33198 reply_id: 131909[/import]

Wow! Thank you for the very quick help. Just out of curiosity, is there a way to do this with physics? Can I apply something like circle:setLinearVelocity to make the circle launch up on a curve and have gravity pull it back down? [import]uid: 14218 topic_id: 33198 reply_id: 131925[/import]

Yes - take a look at the link I sent you, the code does both calculating the trajectory and launching a ball along the same path using the Box2D physics engine built into Corona. [import]uid: 8271 topic_id: 33198 reply_id: 131928[/import]

Very nice, this is what I needed! Thank you!!! [import]uid: 14218 topic_id: 33198 reply_id: 131931[/import]