I’m back just to say I have somme issues with your sample code. I made a little code to show them :
[code]
display.setStatusBar( display.HiddenStatusBar );
local physics = require “physics”
physics.start()
physics.setGravity( 0, 0 )
–physics.setDrawMode( “hybrid” )
local center = display.newCircle( 160, 240, 40 )
physics.addBody( center, “static”, {density=1,radius=20,friction=0})
local function getPositions( x, y, angle, distance )
local mPi = math.pi;local mCos = math.cos;local mSin=math.sin; local mCeil=math.ceil
return { mCeil(x + (distance * mCos((angle-90) * mPi / 180))), mCeil(y + (distance * mSin((angle-90) *mPi / 180))) }
end
– the objects :
local function doObject ( angle, distance, index)
local indices = getPositions( 160, 240, angle, distance )
local object=display.newRoundedRect( indices[1], indices[2], 20,40, 4 )
object.rotation=angle
physics.addBody( object, “dynamic”, { isSensor = true, radius=20,density=1, friction=0, bounce=1 } )
object.joint = physics.newJoint( “pivot”, object, center, 160, 240 )
return object
end
local objects={}
for i=1, 2 do
objects[i]=doObject(i*30, 150,i)
end
local force = 1000
local function doRotation( event )
if event.phase == “began” then
for i=1,#objects do
objects[i]:setLinearVelocity( 0, 0 )
– your code :
local dx, dy = objects[i].x - 160, objects[i].y - 240
local length = math.sqrt(dx * dx + dy * dy)
local scale = force / length
objects[i]:setLinearVelocity(dy * scale, dx * scale)
– my problem :
– 1. objects should turn at the same speed …
– 2. objects should not change rotation sens
end
end
end
center:addEventListener(“touch”,doRotation) [/code]
[import]uid: 9328 topic_id: 32669 reply_id: 129985[/import]