Yes, from what I’ve seen using box2d with flash, cocos2d or anything else rotation is automatically fixed when using prismatic joints. But I may be missing exactly what your talking about horacebury, honestly I’m more interested in figuring out why I can’t get the piston joint to restrict to one axis like it is supposed too.
Here is some code to illustrate what I’m talking about with the axis. You can play with the numbers and add motors, but from what I’ve found there is no way to restrict the movement to one axis using piston/prismatic joints in corona. Hopefully I’m missing something because it works perfect using box2d with anything other than corona.
You can drag the boxes.
[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(0,1)
[/code] [import]uid: 10243 topic_id: 2570 reply_id: 19534[/import]