Hi guys…I conctact you cause i’ve some problems about collision.
I’ve two bodies (one dinamic and one static) and when they collide, the dynamic does not change direction, but it remains pasted at the second object . I post the code down, but is only a part who interest the problem.
local physics = require “physics”
physics.start()
physics.setGravity(0, 0)
physics.setDrawMode(“hybrid”)
local physicsData = (require “shapes”).physicsData(1.0)
local dragon = display.newImage (“dragon4.png”,0,0,true)
dragon.x = W ; dragon.y = H -25
dragon.name = “dragon”
physics.addBody( dragon, “static”, physicsData:get(“dragon4”)
ball = display.newImage (“ball.png”)
ball.x = 240; ball.y = 275
ball.name = “ball”
ball.myName = “ball”
local function onGlobalCollision( event )
if ( event.phase == “began” ) then
print(event.object1.name … " & " … event.object2.name … " collision began" )
vy= ball:getLinearVelocity()
ball:setLinearVelocity(-vy )
end
Runtime:removeEventListener( “collision”, onGlobalCollision )
end
Runtime:addEventListener( “collision”, onGlobalCollision )