Objects overlap, but no collision is detected...

Hello,

I have just started working on a tower defense style game.  I am using OOP in an attempt to keep things manageable, but I am struggling with setting up a collision listener for the towers.

If I draw physics in debug mode, it shows the objects in question overlap, yet there is no collision event thrown.

Tower = {} Tower\_mt = { \_\_index = Tower } function Tower:new( parentGroup, params ) --print("Im in NEW VIRUS") local self = {} setmetatable( self, Tower\_mt ) --A BUNCH OF IRRELEVANT CODE HERE function onLocalCollision( mySelf, event ) if ( event.phase == "began" ) then print( "began: " .. mySelf.type .. " & " .. event.other.type .. " at " .. event.x .. "," .. event.y ) elseif ( event.phase == "ended" ) then print( "ended: " .. event.object1.type .. " & " .. event.object2.type .. " at " .. event.x .. "," .. event.y ) end end -- Add Firing Range Collider print("Printing Params: "..params.spawnX ..",".. params.spawnY ..",".. self.\_myRange) self.\_rangeCollider.isVisible = true physics.addBody( self.\_rangeCollider, "kinematic", {radius=70} ) self.\_rangeCollider.isSensor = true self.\_rangeCollider.collision = onLocalCollision self.\_rangeCollider:addEventListener( "collision", self.\_rangeCollider ) return self end

What I am hoping will happen is that when a new tower is spawned it will instantly start detecting collisions with potential targets.

You might want to start with the collision filters helper sticky in the physics forum. 

Also, take a look at the http://docs.coronalabs.com/api/type/Body/isBodyActive.html state in case the object gets spawned and is at rest.

Hi @guillopuyol,

What “type” of physics objects are the targets? Remember that at least one body in any collision must be “dynamic” type… “kinematic” will not collide with another “kinematic”, for example.

If you’re building a tower defense game, I assume there is no gravity, because the view is looking from above? If so, you can make the range sensors “dynamic”… there is no specific reason to make them kinematic if no physical forces will be applied to them (i.e. gravity).

Hope this helps,

Brent Sorrentino 

You might want to start with the collision filters helper sticky in the physics forum. 

Also, take a look at the http://docs.coronalabs.com/api/type/Body/isBodyActive.html state in case the object gets spawned and is at rest.

Hi @guillopuyol,

What “type” of physics objects are the targets? Remember that at least one body in any collision must be “dynamic” type… “kinematic” will not collide with another “kinematic”, for example.

If you’re building a tower defense game, I assume there is no gravity, because the view is looking from above? If so, you can make the range sensors “dynamic”… there is no specific reason to make them kinematic if no physical forces will be applied to them (i.e. gravity).

Hope this helps,

Brent Sorrentino