Why won't these (dynamically generated) objects collide?

Why won’t the robot objects collide with the line?

[lua]physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9 )

—[[
physics.setDrawMode( “hybrid” )
–]]

level = 1

local lineFilter = { categoryBits = 2, maskBits = 1 }
display.setStatusBar(display.HiddenStatusBar)

local screenW = display.contentWidth
local screenH = display.contentHeight

local background = display.newRect(0,0, screenW,screenH)
background:setFillColor(200,255,200)

local lowtoucharea = display.newRect(0,screenH*0.9,screenW,screenH*0.1)
local hightoucharea = display.newRect(0,screenH*0.8,screenW,screenH*0.1)
hightoucharea:setFillColor(255,0,0)
function makerobot()

local robot =display.newImageRect(“robot”…math.random(1,2)…".png", 306,210)
robot.x = math.random(0,screenW*.9)
robot.y = 500–math.random(-500,-100)
local scaleFactor = 1.0
local physicsData = (require “robot”).physicsData(scaleFactor)
physics.addBody( robot, physicsData:get(“robot”) )
robot:applyAngularImpulse(math.random(-360,360))
–transition.to(robot, {time = math.random(9000/level,15000), y= screenH+500, onComplete = function(self) self.parent:remove(self); self = nil; end })

timer.performWithDelay(1000,makerobot)
end
makerobot()

function highdrawLine( event )

if(event.phase == “ended”) then
box = display.newRect(eventx,eventy,1000,10)
box:setFillColor(255,0,0)
box:setReferencePoint( display.TopLeftReferencePoint )
box.rotation = 90+math.floor(180-math.atan2(eventx - event.x, eventy - event.y)*(180/math.pi))
transition.to(box, {time = 1000, alpha=0, onComplete = function(self) self.parent:remove(self); self = nil; end })
physics.addBody(box, “static”, {filter = lineFilter})

– line = display.newLine(event.xStart, event.yStart, event.x, event.y)
–[[ line = display.newLine(eventx, eventy, event.x,event.y)
line:setColor(255,0,0)
line.width = 10
transition.to(line, {time = 1000, alpha=0, onComplete = function(self) self.parent:remove(self); self = nil; end })
– physics.addBody(line, “static”) --]]
eventx = nil
eventy = nil

end
end
function lowdrawLine( event )
if(event.phase == “began”) then
eventx = event.x
eventy = event.y + 100
end
end

hightoucharea:addEventListener(“touch”, highdrawLine)
lowtoucharea:addEventListener(“touch”, lowdrawLine)[/lua]
robots filter:
[lua] filter = {categoryBits = 1, maskBits = 2},[/lua] [import]uid: 79135 topic_id: 15278 reply_id: 315278[/import]

what is the categoryBits and maskBits value given for Robot object collision filter ? I think its given inside physicsData. Please check whats given.

It should be categoryBits = 1 and maskBits = 2 (if you want the robot to collide only with the line but not other robots) or maskBits = 3 (if you want the robots to collide with the line and with each other) [import]uid: 71210 topic_id: 15278 reply_id: 56434[/import]

It is categoryBits = 1 and maskBits = 2 !
I posted it under the lua code.

The rest of it:

[lua] [“robot”] = {

{

density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -3, 51.5 , -104.5, 1 , -71, -46.5 , 70, -48.5 , 95.5, -45 , 104, -7.5 , 94.5, 61 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -104.5, 1 , -3, 51.5 , -102.5, 58 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { 49.5, -103 , 70, -48.5 , -71, -46.5 , -60, -105.5 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -71, -46.5 , -104.5, 1 , -96.5, -43 }
}
}[/lua] [import]uid: 79135 topic_id: 15278 reply_id: 56450[/import]

It must be something to do with it being genorated-on-the-fly.

This works: (same code but made with the scene)
[lua] box = display.newRect(0,500,1500,10)
box:setFillColor(255,0,0)
box:setReferencePoint( display.TopLeftReferencePoint )
box.rotation = 0
–transition.to(box, {time = 1000, alpha=0, onComplete = function(self) self.parent:remove(self); self = nil; end })
physics.addBody(box, “static”, {filter = lineFilter})
localGroup:insert(box)[/lua]

[import]uid: 79135 topic_id: 15278 reply_id: 56453[/import]

ur robot is using categorybits 2 and maskkbits 12 as per ur previous post.

[lua] [“robot”] = {

{

density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -3, 51.5 , -104.5, 1 , -71, -46.5 , 70, -48.5 , 95.5, -45 , 104, -7.5 , 94.5, 61 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -104.5, 1 , -3, 51.5 , -102.5, 58 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { 49.5, -103 , 70, -48.5 , -71, -46.5 , -60, -105.5 }
} ,
{
density = 1, friction = 0, bounce = 0,
filter = {categoryBits = 2, maskBits = 12},
shape = { -71, -46.5 , -104.5, 1 , -96.5, -43 }
}
}[/lua] [import]uid: 71210 topic_id: 15278 reply_id: 56459[/import]

there is some error in your box.rotation formula which prevents the box to have physical properties.
thats why it worked when u used the above code. [import]uid: 71210 topic_id: 15278 reply_id: 56460[/import]

Sorry about my mistake with the maskBits - I have been trying other things, and adding different objects and such.

Wonder what the problem with it is… I will look :slight_smile: [import]uid: 79135 topic_id: 15278 reply_id: 56513[/import]

It is the:
[lua] box:setReferencePoint( display.TopLeftReferencePoint )[/lua]

that makes the physics not react. [import]uid: 79135 topic_id: 15278 reply_id: 56517[/import]