physics collision, rotation and pivot help

Hi everybody, I’m trying to make the code below working. I have prepared a simplified, commented version just for you :slight_smile:

-- vars  
local balls = {}  
local mW,mH = display.contentWidth\*0.5, display.contentHeight\*0.5  
-- physics  
local physics = require "physics"; physics.start()  
physics.setGravity( 0, 0 ); physics.setDrawMode( "hybrid" )  
  
-- FUNCTIONS  
local function placeBall( anglePerBall, ballspeed )  
 balls[#balls+1] = display.newCircle( mW, mH-50, 20 )   
 balls[#balls].yReference = 50  
 balls[#balls]:rotate( anglePerBall )  
 physics.addBody( balls[#balls], "dynamic", { isSensor = true, radius = 20 } )  
 balls[#balls].id = #balls  
 balls[#balls].delta = ballspeed   
end  
local function mainLoop()  
 for i=1,#balls do  
 balls[i]:rotate(balls[i].delta)   
 end  
end  
  
local function onGlobalCollision( event )  
 if ( event.phase == "began" ) then  
 print( "Global report: " .. event.object1.id .. " & " .. event.object2.id .. " collision began" )  
 end  
 -- MY PROBLEM  
 -- print only once on terminal if "began" / never print if "ended"  
 -- anyway don't laucnh when balls collisions ...  
end  
  
-- GO  
for i=1,2 do  
 placeBallWithJoint( i\*90, i\*3 )  
end  
Runtime:addEventListener("enterFrame", mainLoop)  
Runtime:addEventListener( "collision", onGlobalCollision )  

Thx to wintermuteai1 (http://developer.anscamobile.com/code/orbital-rotation), I tried a workaround and use an orbital rotation this way :
The collision is now ok, still I have an second issue (see comments)

-- 1. add at the beginning :  
local center = display.newCircle( mW, mH, 10 )  
physics.addBody( center, "static")  
  
-- 2. replace placeBall(i\*90, i\*3) with placeBallWithJoint(i\*90, i\*3)  
-- my SECOND ISSUE is in the comment  
local function placeBallWithJoint( anglePerBall, ballspeed )  
 balls[#balls+1] = display.newCircle( mW, mH-50, 20 )   
 -- balls[#balls].yReference = 50 -- don't use yReference trick when using PIVOT  
 -- balls[#balls]:rotate( anglePerBall ) -- don't do rotation here or PIVOT won't work  
 physics.addBody( balls[#balls], "dynamic", { isSensor = true, radius = 20 } )  
 physics.newJoint( "pivot", balls[#balls], center, center.x, center.y)  
 -- place the ball  
 balls[#balls]:rotate( anglePerBall )  
 -- here is my SECOND ISSUE :  
 -- balls don't start at 90 and 180° but a weird 60°....  
  
 balls[#balls].id = #balls  
 balls[#balls].delta = ballspeed   
end  

Of course I have no idea why code1 collision fails and why code2 placement is not the right.

Thx for any hints :)) [import]uid: 9328 topic_id: 20233 reply_id: 320233[/import]