This is definitely a show stopper for me so I’ll post it here. I can’t get the piston joint to constrain to a single axis like it is supposed to.
Here is a link to a working Piston joint in AS3 with box2d.
http://www.emanueleferonato.com/2009/02/03/box2d-joints-prismatic-joints/
I may be doing something wrong but I’ve been trying for weeks and can’t get it to work. Here is some sample code. You can pick up the big box and push the medium box off the y axis which it is supposed to be restricted too.
[code]
local physics = require(“physics”)
physics.start()
physics.setDrawMode(“debug”)
display.setStatusBar( display.HiddenStatusBar )
local function startDrag( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
event.target.bodyType = “kinematic”
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
event.target.bodyType = “dynamic”
end
end
return true
end
local bigBlock = display.newRect( 0, 0, 128, 128 )
bigBlock.x = 160; bigBlock.y = 0
physics.addBody( bigBlock, { density=5.0, friction=0.4, bounce=0.2 } )
local anchor = display.newRect( 0, 0, 32, 32 )
anchor.x = 160; anchor.y = 400
physics.addBody( anchor, “static” )
local block = display.newRect( 0, 0, 64, 64 )
block.x = 160; block.y = 300
physics.addBody( block, { density=3.0, friction=0.4, bounce=0.2 } )
bigBlock:addEventListener( “touch”, startDrag )
block:addEventListener( “touch”, startDrag )
myJoint = physics.newJoint( “piston”, block, anchor, anchor.x, anchor.y, 0,5 )
myJoint.isLimitEnabled = true
myJoint:setLimits(1,1)
[/code] [import]uid: 10243 topic_id: 6007 reply_id: 306007[/import]