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.