Hi everyone,
I’m having a problem working with multiple physics objects connected with joints. My goal is to create a basket that is attached to the end of a long arm. The arm will rotate counter clockwise with the basket maintaining an upright orientation as it stays attached by a friction joint or a pivot. Keep in mind that I’m scaling down both images in Corona.
Here is the code that I have so far.
local basketBack = display.newImageRect( “images/general/swingBasket/basketBack.png”, 360, 306 )
basketBack.xScale = 1/6
basketBack.yScale = 1/6
basketBack.x = xP
basketBack.y = yP
--basketBack.isFixedRotation = true
physics.addBody(basketBack, “dynamic”,
{ density = 1, friction = 0, bounce = 0, isSensor=false, shape = backShape[1]},
{ density = 1, friction = 1, bounce = 0, isSensor=false, shape = backShape[2]},
{ density = 1, friction = 1, bounce = 0, isSensor=false, shape = backShape[3]})
local basketFront = display.newImageRect( “images/general/swingBasket/basket.png”, 360, 209 )
basketFront.xScale = 1/6
basketFront.yScale = 1/6
basketFront.x = xP
basketFront.y = yP + 8
physics.addBody(basketFront, “dynamic”,{ density = 3, friction = 0, bounce = 0, isSensor=true, shape = sensorShape})
local basketArm = display.newImageRect( “images/general/swingBasket/basketArmSmall.png”, 978, 47 )
basketArm:setReferencePoint(display.CenterRightReferencePoint)
basketArm.xScale = 1/6
basketArm.yScale = 1/5.75
basketArm.x = xP + 141.8 --66.8
basketArm.y = yP - 18.2
physics.addBody(basketArm, “static”,{ density = 1, friction = 0, bounce = 0, isSensor=false, shape = armShape[1]},
{ density = 3, friction = 0, bounce = 0, isSensor=false, shape = armShape[2]})
local frontBackJoint = physics.newJoint( “weld”, basketBack, basketFront, xP, yP )
local backJoint = physics.newJoint( “friction”, basketBack, basketArm, xP, yP - 18.2 )
backJoint.maxForce = 2
backJoint.maxTorque = .1
I also have this in my main file
transition.to(swingBasket.arm, {time = 2000, rotation = -180})
its referring to the arm just to be as clear as possible.
The reason I’m welding the front and the back is so that something can be put in between the two so it looks like the basket is actually holding an object.
I’m trying to rotate the arm from the right reference point but after I scale the object is seems that the joint develops and error and doesn’t recognize the scaling. Also when I rotate from the centerRightReferencePoint the frictionjoint just remains in the initial position and the basket doesn’t move with the arm.
If anyone can help clear up I would be very grateful.
Rob