I think other may have faced the same problems. I try the tip at http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/ but it doesn’t work for me either. Below is the code
local physics = require "physics"
physics.start()
physics.setVelocityIterations( 6 )
physics.setPositionIterations( 16 )
local obj = display.newRect(0,0, 10,10)
obj:setFillColor(255, 0 , 0)
obj.x = display.contentWidth / 2
obj.y = 30
physics.addBody(obj, "static")
obj.isBullet = true
local target = display.newRect(0,0, 10,10)
target.x = display.contentWidth / 2
target.y = 430
physics.addBody(target, "static")
target.isSensor = true
local function targetCollision(e)
if e.phase == "began" then
print("Collision occurred")
target:removeSelf()
target = nil
end
end
target:addEventListener("collision", targetCollision)
local function objForce(e)
if e.phase == "began" then
obj.bodyType = "dynamic"
obj:applyForce(0, 0.9, obj.x, obj.y)
end
end
obj:addEventListener("touch", objForce)
If I set target.isSensor = fase the collision happen but the obj may bounce sometimes.
Any solution to this? Thank you.
Steve [import]uid: 84159 topic_id: 17158 reply_id: 317158[/import]