collision between a line and newrect

Hello,

Is not detecting the collision between the “line” that is rising and the “paredeALinha”. 

I want to erase the line when they clash, but it is not working. 

does anyone know why?

full code on github

https://github.com/Filipeasr/CoronaGame

--... --colisoes.lua --... function onCollisionParedeCimaLinha( event ) if ( event.phase == "began" ) then if (event.object2.myName == "linha")then if (event.object1.myName == "paredeALinha" ) then event.object2:removeSelf() print "onCollisionParedeCimaLinha" end end end end --... --scene2.lua --... lines = {} local prev\_x local prev\_y line\_number = 1 local line\_width = 5 function drawLine (e) local group = self.view if e.phase == "began" then prev\_x = e.x prev\_y = e.y elseif e.phase == "moved" then lines[line\_number] = display.newLine(group,prev\_x, prev\_y, e.x, e.y) lines[line\_number].alpha = .5 lines[line\_number].strokeWidth = line\_width dist\_x = e.x - prev\_x dist\_y = e.y - prev\_y fisica.addBody(lines[line\_number], "static", { density = 3, friction = 0, bounce = 0, shape = {0, 0, dist\_x, dist\_y, 0, 0} } ) prev\_x = e.x prev\_y = e.y line\_number = line\_number + 1 lines.isSensor = false lines.myName = "linha" print(lines.myName) elseif e.phase == "ended" then print "drawLine" for i=1, line\_number do transition.to( lines[i], {time=4100000, y = -500000} ) end end return lines[line\_number] end Runtime:addEventListener( "collision", onCollisionParedeCimaLinha) --... --paredes.lua --... paredeALinha = display.newRect(0, -10, 700, 10) fisica.addBody(paredeALinha, "kinematic") paredeALinha.isFixedRotation=true paredeALinha.myName = "paredeALinha" paredeALinha.isVisible = false

Lines don’t work as physics objects and should be avoided. You should use display.newRect instead.

Hi @filipe.asr,

A slight correction on this… lines can be physics objects, but with some restrictions, i.e. they must be “static” type. However, I generally do not recommend using lines as physics bodies. As Tom suggests, a very thin rectangle would be more reliable.

Also, in your code, you’ve declared the physics “shape” for the line, but you haven’t done it correctly (3 vertices, and 2 of them the same). I recommend that you read through the physics guides carefully and fully understand the usage and limitations before you proceed:

http://coronalabs.com/resources/tutorials/physics-box2d/

Take care,

Brent

Lines don’t work as physics objects and should be avoided. You should use display.newRect instead.

Hi @filipe.asr,

A slight correction on this… lines can be physics objects, but with some restrictions, i.e. they must be “static” type. However, I generally do not recommend using lines as physics bodies. As Tom suggests, a very thin rectangle would be more reliable.

Also, in your code, you’ve declared the physics “shape” for the line, but you haven’t done it correctly (3 vertices, and 2 of them the same). I recommend that you read through the physics guides carefully and fully understand the usage and limitations before you proceed:

http://coronalabs.com/resources/tutorials/physics-box2d/

Take care,

Brent