Hey guys,
It must be something trivial I am missing.
What is the proper way to rotate complex physics objects (I do not mean applying torque, but rather changing the rotation property or the equivalent)
I am trying to build physics objects that are made up of more than one element, and to easily allow the developer who uses these objects to rotate them freely.
Here is an example of a two-part piston object, any help is appreciated.
[lua]-- main.lua
physics = require “physics”
physics.start()
physics.setScale( 80 )
physics.setDrawMode( “hybrid” )
print “\n\n\n\n-------------”
function piston( x,y,dir, rotation )
local group = display.newGroup()
– create the rod portion of the piston
local rod = display.newRect( group, x+10,y,20,80 )
rod:setFillColor( 150,150,150 )
rod.rotation = rotation
– create the cyllinder
local body = display.newRect( group, x,y,40,80 )
body:setFillColor( 90,90,90 )
body.rotation = rotation
–group.rotation = rotation – another non-working way, instead of the above two
physics.addBody( rod, “dynamic” )
physics.addBody( body, “static” )
– connect the two together
local joint = physics.newJoint( “piston”, body, rod, body.x,body.y, 0,dir )
joint.isMotorEnabled = true
joint.motorSpeed = 400
joint.maxMotorForce = 5000
joint.isLimitEnabled = true
joint:setLimits( 0, 0 )
– after a second, let it pump
timer.performWithDelay( 1000, function() joint:setLimits( 0, 40 ) end )
end
piston( 50,100 ,1, 0 )
piston( 140,100,1, 20 ) – rotated piston
piston( 220,100,-1, 20 ) – rotated up-facing piston[/lua]
[import]uid: 145050 topic_id: 26841 reply_id: 326841[/import]