possible collision bug when code is separated into another module

Hi,

I have come across something interesting, it may be a bug or I might have missed something…

I have a ball that moves to the right when you touch the screen. There is a big square in its way. There is a little square at the top of the screen which moves the big square up (and out of the way of the ball)

If I put all the code in the one lua file everything works, if the big square is moved up, then the ball goes underneath it no problems, no collision at all.

But as soon as I move it into two files, the square creation into another lua file, for some reason even when the big square is out of the way, the ball seems to hit an invisible object.

My code is below…

thanks

main.lua

local square = require "square"  
  
local physics = require "physics"  
physics.start( true )  
physics.setDrawMode("normal") -- set to "debug" or "hybrid" to see collision boundaries  
--physics.setDrawMode("hybrid")  
physics.setGravity( 0, 9.8 ) --\> 0, 9.8 = Earth-like gravity  
  
  
  
local cel = display.newRect(0, 0, display.contentWidth, 10)  
cel.y = 900  
physics.addBody(cel, "static" )   
   
 local ball = display.newCircle( 100, 100, 30 )  
 ball.y = 900  
 physics.addBody(ball, "dynamic" )   
   
  
local squareInstance = square.CreateSquare()  
local square1 = display.newRect(100 , 100 , 50, 50)  
  
   
function movement(event)  
   
 ball:applyLinearImpulse( 0.1, 0, ball.x, ball.y )  
   
end  
   
 function test(event)  
   
   
 squareInstance.y = squareInstance.y - 10  
 return true  
   
 end  
square1:addEventListener( "touch", test )  
Runtime:addEventListener( "touch", movement )  
  

square.lua

[code]
module(…, package.seeall)
function CreateSquare()

– create group to return
local localGroup = display.newGroup ()

local square = display.newRect(500 , 800 , 100, 100)
physics.addBody(square, “static” )
localGroup:insert(square)

function SquareCollision()

print(“ouch”)
end

square:addEventListener( “collision”, SquareCollision )

return localGroup

end

[/code] [import]uid: 67619 topic_id: 20184 reply_id: 320184[/import]

i understand this is occurring because it is in a displayGroup, but is this a bug? or am I missing something? [import]uid: 67619 topic_id: 20184 reply_id: 78831[/import]

you are not missing anything its true currently there is no collision if two physics objects are in different group.
:slight_smile: [import]uid: 12482 topic_id: 20184 reply_id: 78848[/import]

hgvyas - at the moment there is collision… there is collision even when the object has been moved… its def to do with the groups and its own coordinates… [import]uid: 67619 topic_id: 20184 reply_id: 78853[/import]

surely there must be a work around? [import]uid: 67619 topic_id: 20184 reply_id: 78855[/import]

I can inspect the children and move each child… which works… but sure there must be another way to do this? Basically I am trying to move my character on the screen as the character moves… the camera moves with him… but he seems hit invisible walls (which were walls at one point, but as the character moves down the walls are moved up) which is what I was trying to showcase my this simple bit of code… other people have surely moved the camera around yeah? [import]uid: 67619 topic_id: 20184 reply_id: 78858[/import]