Hi,
I have been working on code that calls a function on a collision with different elements in my game. It was working fine and I could see the results of my function (printing for now) in the Terminal when they collided. However, after anywhere from 9-15 collisions, it would not sense a collision or print the output. When I put in collision filters, it would stop sensing and printing after 1-3 collisions. Can anyone help with this? Is this a bug or just and error on my part?
Thanks in advance!
Here is my code:
[code]
local function shark()
local sharkCollisionFilter = {categoryBits = 1, maskBits = 14}
local shark = movieclip.newAnim({ “Images/Animations/shark1.png”, “Images/Animations/shark2.png”, “Images/Animations/shark3.png” })
shark:setSpeed(0.22)
shark:setDrag{
drag=true,
limitX=true,
limitY=false,}
physics.addBody ( shark, { filter = sharkCollisionFilter})
shark.bodyType = “kinematic”
shark:play()
end
local function sub()
local subCollisionFilter = {categoryBits = 8, maskBits = 1 }
local sub = display.newImage (“Images/sub.png”, 500, (math.random(300)))
physics.addBody( sub, {isSensor = true, filter = subCollisionFilter})
transition.to( sub, { time=2500, x=(-30), y=(math.random(1,320)), onComplete = removeSub })
end
function diver()
local diverCollisionFileter = {categoryBits = 4, maskBits = 1}
local diver = display.newImage(“Images/diver.png”, 500, 100 )
physics.addBody( diver, {isSensor = true, filter = diverCollisionFilter})
transition.to( diver, { time=2500, x=(-30), y=(100), onComplete = removeDiver })
end
function Torpedo()
local torpedoCollisionFilter = {categoryBits = 2, maskBits = 1}
local torpedo1 = display.newImage(“Images/torpedo.png”, sub.x, sub.y)
local torpedo2 = display.newImage(“Images/torpedo.png”, sub.x, sub.y)
physics.addBody ( torpedo1, { isSensor=true, radius= 8, })
physics.addBody ( torpedo2, { isSensor=true, radius= 8, })
transition.to( torpedo1, { time=700, x=(-30), y=(sub.y + 50), onComplete = removeTorpedo1} )
transition.to( torpedo2, { time=700, x=(-30), y=(sub.y - 50), onComplete = removeTorpedo2} )
end
–(rest of code here)
[/code] [import]uid: 38000 topic_id: 14486 reply_id: 314486[/import]