Making an object change position when it hits another object

local skipbar = display.newRect( 0, 0, 105, 20)
skipbar:setFillColor( 12, 255, 255, 1000)
skipbar.x = 245
skipbar.y = 600
localGroup:insert(skipbar)
physics.addBody (skipbar, “static”, {bounce=0.2, density=1.0})

local skip = function()
ball.y = 800
end
skipbar:addEventListener( “collision”, skip )
I tried that and it didn’t work

PS thanks in advance!
[import]uid: 86879 topic_id: 16820 reply_id: 316820[/import]

hope you are doing thins correctly. post the full code if you want me to verify.
if everything is done properly check the terminal window. you may be having some error.
most probably this-
ERROR: Cannot translate an object before collision is resolved.
in that case just set the value for y after a few seconds. use a timer. :slight_smile:
[lua] timer.performWithDelay(1000, function() ball.y = 800 end ) [/lua] [import]uid: 71210 topic_id: 16820 reply_id: 63005[/import]

Hay! Thanks for the quick response! Where do I put the timer delay? Also that is the exact error code that I am getting in the terminal!! [import]uid: 86879 topic_id: 16820 reply_id: 63010[/import]

Put it inside the skip functio in event.phase ==“began”
[import]uid: 71210 topic_id: 16820 reply_id: 63013[/import]

local skipbar = display.newRect( 0, 0, 105, 20)
skipbar:setFillColor( 12, 255, 255, 1000)
skipbar.x = 245
skipbar.y = 600
localGroup:insert(skipbar)
physics.addBody (skipbar, “static”, {bounce=0.2, density=1.0})

local function skip( event )
if event.phase == “began” then
timer.performWithDelay(1000, function() ball.y = 800 end )

end
end
skipbar:addEventListener( “collision”, skip )
This is what I have now, I am no longer getting an error, but it is only bouncing off the bar =( [import]uid: 86879 topic_id: 16820 reply_id: 63014[/import]

make sure that you have declare ball above the skip function.
also try printing something inside the skip function. just to make sure that its getting called. if the above din’t work post me the full code and I will have a look at it. :slight_smile: [import]uid: 71210 topic_id: 16820 reply_id: 63047[/import]

do you have an email, it is 500 lines =) [import]uid: 86879 topic_id: 16820 reply_id: 63050[/import]

send it to renjith@technowand.com [import]uid: 71210 topic_id: 16820 reply_id: 63052[/import]