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!

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. :)
 timer.performWithDelay(1000, function() ball.y = 800 end )

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!!

Put it inside the skip functio in event.phase =="began"

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 =(

views:1347 update:2011/10/25 9:10:48
corona forums © 2003-2011