Hello, i have this code here
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require("physics") physics.start() function scene:createScene( event ) local group = self.view local rect = display.newRect( 50, 50, 100, 150 ) -- left, top, w, h rect.x = 150 rect.y = 350 rect.name = "rotate" rect:setFillColor( 255,255,0 ) physics.addBody(rect, "static", {density = 1.0, friction = 0.3, bounce = 0.2}) group:insert(rect) local rect2 = display.newRect( 150, 150, 150, 150) -- left, top, w, h rect2.x = 150 rect2.y = 150 rect2:setFillColor( 255,255,255 ) rect2.name = "falloff" physics.addBody(rect2, "dynamic", {density = 1.0, friction = 0.3, bounce = 0.2}) group:insert(rect2) function onCollision( event ) if(event.object1.name == "rotate" and event.object2.name == "falloff") then physics.newJoint( "weld", rect2, rect, rect2.x,rect2.y ) elseif(event.object1.name == "falloff" and event.object2.name == "rotate") then physics.newJoint( "weld", rect2, rect, rect2.x,rect2.y ) end end function rollingz(event) rect.rotation = rect.rotation + 1 end end function scene:enterScene( event ) Runtime:addEventListener("enterFrame", rollingz) Runtime:addEventListener( "collision", onCollision ) end function scene:exitScene( event ) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
I want when that rect and rect2 in collision the rect2 stick to rect and follow the rotation of rect and when I tap again that rect2 is unstick and jumping
I read this thread http://forums.coronalabs.com/topic/3166-making-physics-objects-stick-to-one-another/ but still dont understand
