Hi, I’ve started building my spawns table. I can’t figure out how to change the isSensor to false once the objects collide so that I do not get the second “hit” when the objects finally part.
Also is there a better way to do this. I’m not going to be using physics in my game I just want the sensor feature. Thanks in advance.
–
physics = require( “physics” )
physics.start()
physics.setGravity(0,0)
function setup()
watch = 4
hitBox=display.newRect(100,200,60,160)
physics.addBody( hitBox, {isSensor = true} )
hitBox:addEventListener(“collision”,hit)
timer.performWithDelay(10,mix,1)
end
function hit(obj)
if obj.sense == true then --this is part of the problem
print(“hit”)
obj:setFillColor(255,75,75)
obj.sense = false --this is part of the problem
end
end
setup()
function spawnWall(attributes)
–obj = display.newImage(attributes.image)
obj = (attributes.rect)
obj.objTable = attributes.objTable
obj.index = #obj.objTable + 1
obj.objTable[obj.index] = obj
obj.group = attributes.group or nil
obj.group:insert(obj)
obj.type = unbreakable
physics.addBody( obj, {isSensor = true} )
obj.sense = true --this is part of the problem
obj:setFillColor(255,255,75)
transition.to(obj, {y=470,time=3000,onComplete=killObj})
return obj
end
localGroup = display.newGroup()
spawnTable = {}
function spawnWall_1()
for i = 1,1 do
--spawns = spawnWall({image = “image1.png”, --add image once designed
spawns = spawnWall({rect = display.newRect(0,-50,200,20),
objTable = spawnTable,
group = localGroup,
})
end
end
spawnWall_1()