My code detects the collision properly but the problem is that it detects the collision only after the collision between the center of my image …i want it to detect the collision as soon as the border / circumference hits the object … also in case of collecting coins I have the same issue … I have tried using preCollision / collision / postCollision methods … made no difference
im not sure if you are using physics.addBody? You might have set the physics body to be smaller than the image itself making it seem like its only activating in the center of the image? Should post code on how you are setting physics to the image and the size of the image.
local jetSheet = { width=133, height=41, numFrames=4, sheetContentWidth=532, sheetContentHeight=41}
local jetSprite = graphics.newImageSheet(myGameSettings.jet, jetSheet)
local sequenceJet ={name=“jet”,frames= {1,2,3,4}, time = 340,}
local jet = display.newSprite(jetSprite,sequenceJet)
jet.myName=“jet”
jet.x = 0; jet.y = _H;
physics.addBody(jet, “static”,{density = 1, bounce = 0.1, friction = 2,radius = 0,})
jet:setLinearVelocity( 0, 0 )
jet.angularVelocity = 0
jet.collided = false
jet:play()
local jetstart = transition.to(jet, {time = 2000, y = centerY-100, x = 70})
local coin = display.newImage(“coin.png”, 1200,300); coin.myName=“coin”
physics.addBody(coin, “static”,{density = 1, bounce = 0.1, friction = 2, radius = 50})
function coin:preCollision( event )
local platform = event.other
if platform.myName == “jet” then
self.isVisible = false
event.contact.isEnabled = false
countcoin()
end
end
coin:addEventListener( “preCollision” )
note :- as soon as i set the radius of the jet to 60 … the jet shows an erratic behaviour ( it blows off like a paper) as soon as i begin
physics.addBody(jet, "static",{density = 1, bounce = 0.1, friction = 2,radius = 0,})
You for sure don’t have a physics body on your jet since you set it to 0. Also there is a “,” at the end may be causing you problems?
From corona docs on using radius:
physics.addBody( jet, { density=1.0, friction=0.3, bounce=0.2, radius=25 } )
Next point, 2 static bodies cannot interact with each other so the collision will never happen. They should be dynamic?
If the jet is showing erratic behaviour it could be in your transition or somewhere else, but a few things should above should be fixed first and maybe you will get different results?
Just found out another issue … if my jet passes through the same location where there was a collision ( an sprite sheet showing explosion is played ) … the jet aslo explodes
function plane:preCollision( event )
local platform = event.other
if platform.myName == “missile” then
event.contact.isEnabled = false
if self.isVisible == true then
targetsDestroyed = targetsDestroyed +1;
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
end
self.isVisible = false
end
if platform.myName == “jet” then
event.contact.isEnabled = false
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
self.isVisible = false
jet.isVisible=false
if jet.collided == false then
jet.collided = true
jet.bodyType = “static”
applyForceToJet = false
gameOver()
end
end
if platform.myName == “shieldCover” then
event.contact.isEnabled = false
if self.isVisible == true then
if shieldCover.isVisible == true then
targetsDestroyed = targetsDestroyed +1;
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
self.isVisible = false
end
end
end
end
plane:addEventListener( “preCollision” )
thnx 4 d reply … i did removed the “,” and added the value of radius = 25 … same erratic problem … and ya i change my jet to dynamic after the transition is over
im not sure if you are using physics.addBody? You might have set the physics body to be smaller than the image itself making it seem like its only activating in the center of the image? Should post code on how you are setting physics to the image and the size of the image.
local jetSheet = { width=133, height=41, numFrames=4, sheetContentWidth=532, sheetContentHeight=41}
local jetSprite = graphics.newImageSheet(myGameSettings.jet, jetSheet)
local sequenceJet ={name=“jet”,frames= {1,2,3,4}, time = 340,}
local jet = display.newSprite(jetSprite,sequenceJet)
jet.myName=“jet”
jet.x = 0; jet.y = _H;
physics.addBody(jet, “static”,{density = 1, bounce = 0.1, friction = 2,radius = 0,})
jet:setLinearVelocity( 0, 0 )
jet.angularVelocity = 0
jet.collided = false
jet:play()
local jetstart = transition.to(jet, {time = 2000, y = centerY-100, x = 70})
local coin = display.newImage(“coin.png”, 1200,300); coin.myName=“coin”
physics.addBody(coin, “static”,{density = 1, bounce = 0.1, friction = 2, radius = 50})
function coin:preCollision( event )
local platform = event.other
if platform.myName == “jet” then
self.isVisible = false
event.contact.isEnabled = false
countcoin()
end
end
coin:addEventListener( “preCollision” )
note :- as soon as i set the radius of the jet to 60 … the jet shows an erratic behaviour ( it blows off like a paper) as soon as i begin
physics.addBody(jet, "static",{density = 1, bounce = 0.1, friction = 2,radius = 0,})
You for sure don’t have a physics body on your jet since you set it to 0. Also there is a “,” at the end may be causing you problems?
From corona docs on using radius:
physics.addBody( jet, { density=1.0, friction=0.3, bounce=0.2, radius=25 } )
Next point, 2 static bodies cannot interact with each other so the collision will never happen. They should be dynamic?
If the jet is showing erratic behaviour it could be in your transition or somewhere else, but a few things should above should be fixed first and maybe you will get different results?
Just found out another issue … if my jet passes through the same location where there was a collision ( an sprite sheet showing explosion is played ) … the jet aslo explodes
function plane:preCollision( event )
local platform = event.other
if platform.myName == “missile” then
event.contact.isEnabled = false
if self.isVisible == true then
targetsDestroyed = targetsDestroyed +1;
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
end
self.isVisible = false
end
if platform.myName == “jet” then
event.contact.isEnabled = false
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
self.isVisible = false
jet.isVisible=false
if jet.collided == false then
jet.collided = true
jet.bodyType = “static”
applyForceToJet = false
gameOver()
end
end
if platform.myName == “shieldCover” then
event.contact.isEnabled = false
if self.isVisible == true then
if shieldCover.isVisible == true then
targetsDestroyed = targetsDestroyed +1;
explosion.xScale = 1; explosion.yScale = 1; explosion.x = self.x; explosion.y = self.y; explosion.isVisible = true; explosion:play();
self.isVisible = false
end
end
end
end
plane:addEventListener( “preCollision” )
thnx 4 d reply … i did removed the “,” and added the value of radius = 25 … same erratic problem … and ya i change my jet to dynamic after the transition is over