[Resolved] Should be simple... Moving an object up and down smoothly

Like I said it should be simple all I need to do is move an object up and down smoothly. I have a platform game and I need a object to move back and forth or up and down in between two other objects to create an obstacle. By the way I have looked for the answer on the form but I can’t find it. What I have tried so far is bounce and transition to but bounce is to fast and transition to only goes one way.

Avery [import]uid: 184688 topic_id: 33199 reply_id: 333199[/import]

Actually transitions work using onComplete for this - run this plug and play;

[lua]local platform = display.newRect( 50, 100, 80, 40 )

local transLeft

local function transRight()
transition.to(platform, {time=1500, x=220, onComplete=transLeft})
end

transLeft = function()
transition.to(platform, {time=1500, x=100, onComplete=transRight})
end

transRight()[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 33199 reply_id: 131885[/import]

Thanks so much! I tweaked it a little and it works great! Thanks for the rapid response, my game is getting pretty good!

Avery [import]uid: 184688 topic_id: 33199 reply_id: 131887[/import]

For things that go back and forth, using something other than the default linear easing can make a big difference in the look.

You might want to try this as one of the params inside your transition.to calls: transition=easing.inOutQuad

Jay
[import]uid: 9440 topic_id: 33199 reply_id: 131894[/import]

If you are using physics you might want to use a motor on the moving object as I’ve found that absolute positioning (as transitions would apply) can cause objects to disappear because their positioning fights the physics engine. [import]uid: 8271 topic_id: 33199 reply_id: 131896[/import]

Thanks for all your help. But I am just going to stick with the first way because it works perfectly in my situation. [import]uid: 184688 topic_id: 33199 reply_id: 131964[/import]

Marked as “Resolved” :slight_smile: [import]uid: 52491 topic_id: 33199 reply_id: 131980[/import]

Actually transitions work using onComplete for this - run this plug and play;

[lua]local platform = display.newRect( 50, 100, 80, 40 )

local transLeft

local function transRight()
transition.to(platform, {time=1500, x=220, onComplete=transLeft})
end

transLeft = function()
transition.to(platform, {time=1500, x=100, onComplete=transRight})
end

transRight()[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 33199 reply_id: 131885[/import]

Thanks so much! I tweaked it a little and it works great! Thanks for the rapid response, my game is getting pretty good!

Avery [import]uid: 184688 topic_id: 33199 reply_id: 131887[/import]

For things that go back and forth, using something other than the default linear easing can make a big difference in the look.

You might want to try this as one of the params inside your transition.to calls: transition=easing.inOutQuad

Jay
[import]uid: 9440 topic_id: 33199 reply_id: 131894[/import]

If you are using physics you might want to use a motor on the moving object as I’ve found that absolute positioning (as transitions would apply) can cause objects to disappear because their positioning fights the physics engine. [import]uid: 8271 topic_id: 33199 reply_id: 131896[/import]

Thanks for all your help. But I am just going to stick with the first way because it works perfectly in my situation. [import]uid: 184688 topic_id: 33199 reply_id: 131964[/import]

Marked as “Resolved” :slight_smile: [import]uid: 52491 topic_id: 33199 reply_id: 131980[/import]