Collision with physics (need help)

Hello,

I have been using this collision code when a ball touches line. When the ball touches line, there is another line “line2” that pops up in a different position. The ball later SHOULD touch line2 and perform a collision. The problem is every time i try to add physics to line2, the simulator crashes. Can i not add physics to collision objects? Any help please?

Thanks.

[code]
ball.myName = “ball”
line.myName = “line”

ball:addEventListener(“collision”,ball)

function ball:collision (event)
if event.other.myName == “line” then

local line2=display.newImageRect(“line.png”,400,10)
line2.x=display.contentWidth/2
line2.y=display.contentHeight/1.3
line2.rotation=30

physics.addBody(line2, “static”, {friction=0.3,bounce=0.3})

end
end
[import]uid: 23689 topic_id: 12372 reply_id: 312372[/import]

Since i can not see the rest of your code I have no clue if this is going to work but here is a stab in the dark…

The first thing that pops out at me is

local line2=display.newImageRect(“line.png”,400,10)

being defined in your collision handler.

instead define the variable out side ( above your handler )

local line2

then inside your function you can assign it.

line2=display.newImageRect(“line.png”,400,10)

LUA is a top down language and it’s logic process may be messing you up ( it’s gotten me countless times ).

Larry Meadows
DoubleSlashDesign.com

[import]uid: 11860 topic_id: 12372 reply_id: 45121[/import]