Physics bodys changing per objects collision

Hi people
i am creating a drag, spawner system, all the images have physics, but only the ball and objects can collide and use their physics, the blocks cant collide with other objects and cant use their physics, what i can use to create some like that?

Thank you [import]uid: 26056 topic_id: 21093 reply_id: 321093[/import]

If I understand what you are asking you will need to listen for collision events. Check out http://developer.anscamobile.com/content/game-edition-collision-detection and see if that helps. You can then have objects do different things when a collision happens. [import]uid: 80890 topic_id: 21093 reply_id: 83395[/import]

Yeh i think the same, but i am using tables to create the objects and i dont know how i can use tables with collision functions.

with a normal object:

function object:collision (event)  
 if event.phase == "began" then  
 --.....  
 return true  
 end  
end  
  
object:addEventListener("collision",object)   

and using tables like:

local object={}  

how will be the function?

Thanks for the help
[import]uid: 26056 topic_id: 21093 reply_id: 83405[/import]

up [import]uid: 26056 topic_id: 21093 reply_id: 83666[/import]

Check out this past post http://developer.anscamobile.com/forum/2011/08/23/how-do-you-write-collision-detection-multiple-objects-same-name

Towards the bottom you can see a sample using tables. You can also give each object within your tables names and then react differently to each object based on the name. [import]uid: 80890 topic_id: 21093 reply_id: 83772[/import]

this link dont help me,because is different of my problem, my functions is:

local variable={}  
  
function variable[#variable]:collision(event)  
 if (event.other.name=="name") then  
 return true  
 end  
 end  
 variable[#variable]:addEventListener("collision",variable[#variable])  

i think that with tables i should use this code, but it dont work, i really need to resolve this simples problem, what i need to change on this function to work with my table variable? [import]uid: 26056 topic_id: 21093 reply_id: 84098[/import]

–[[
drop this code in a lua file and try it. I think this is what your after. This will create 3 rectangles and a floor. The 3 rectangles are in a table and the table is passed to the function. Have your terminal open so you can see the output.
–]]

display.setStatusBar( display.HiddenStatusBar )

_W,_H = display.contentWidth, display.contentHeight

local physics = require(“physics”)
physics.start()

local myRectangle1 = display.newRect(0, 0, 150, 50)
myRectangle1.strokeWidth = 3
myRectangle1:setFillColor(140, 140, 140)
myRectangle1:setStrokeColor(180, 180, 180)
myRectangle1.x = _W / 2 * .50
myRectangle1.y = _H / 2 * .30
myRectangle1.myName = “myRectangle1”
physics.addBody(myRectangle1, “dynamic”, { density=1.0, friction=0.5, bounce=0.5 })

local myRectangle2 = display.newRect(0, 0, 150, 50)
myRectangle2.strokeWidth = 3
myRectangle2:setFillColor(140, 140, 140)
myRectangle2:setStrokeColor(180, 180, 180)
myRectangle2.x = _W / 2 * .80
myRectangle2.y = _H / 2 * .20
myRectangle2.myName = “myRectangle2”
physics.addBody(myRectangle2, “dynamic”, { density=1.0, friction=0.5, bounce=0.5 })

local myRectangle3 = display.newRect(0, 0, 150, 50)
myRectangle3.strokeWidth = 3
myRectangle3:setFillColor(140, 140, 140)
myRectangle3:setStrokeColor(180, 180, 180)
myRectangle3.x = _W / 2 * 1.20
myRectangle3.y = _H / 2 * .50
myRectangle3.myName = “myRectangle3”
physics.addBody(myRectangle3, “dynamic”, { density=1.0, friction=0.5, bounce=0.5 })

local floor = display.newRect(0, 0, _W, 20)
floor.strokeWidth = 3
floor:setFillColor(140, 140, 140)
floor:setStrokeColor(180, 180, 180)
floor.myName = “floor”
floor.x = _W / 2
floor.y = _H / 2 * 2.0
physics.addBody(floor, “static”, { density=3.0, friction=0.5, bounce=0.3 })

local variable={myRectangle1, myRectangle2, myRectangle3}

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

print( self.myName … ": collision began with " … event.other.myName )

elseif ( event.phase == “ended” ) then

print( self.myName … ": collision ended with " … event.other.myName )

end
end

variable[#variable].collision = onLocalCollision
variable[#variable]:addEventListener( “collision”, variable[#variable] ) [import]uid: 80890 topic_id: 21093 reply_id: 84103[/import]

It works and is really what i need, thank you very much for all the help weberkeith :slight_smile: [import]uid: 26056 topic_id: 21093 reply_id: 84256[/import]

Glad I could help. Good luck with your game. [import]uid: 80890 topic_id: 21093 reply_id: 84300[/import]