setRotationLimits() on distance joints

I’m trying to create a simple simulation with an air balloon and a basket hanging under it.  When the user swipes his/her finger against the balloon, a temporary object is created that pushes against it.  To connect the basket to the balloon, I created two distance joints.  This allowed me to put a little bit of “stretch” into the basket as it hung, so that it bounces up and down a bit (but not too much) when the balloon is moved harder.  The problem I have is that I cannot setRotationLimits() on a distance joint, so the basket will sometimes circle the entire balloon, instead of staying at the bottom.  I tried the same thing with a rope joint, but the fact that those can bend presented other problems.  I also tried a pivot joint, which does allow me to set rotation limits, but then I lose the bit of bounciness that I got from the distance joint.  I also tried combining the two distance joints going out from the balloon to the basket with a pivot joint from the center of each with set rotation limits.  The problem with that is that I lost my bounciness again.

Is there any way to set rotation limits on distance joints?  It would be incredibly useful?  Or perhaps a hack that you might suggest (e.g., invisible rects welded to the balloon to stop the basket from going to far).

I did a hot air balloon experiment some time ago.  I’m not sure if it will help, but you can see the code here:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/experiments/003_hotAirBalloon.zip

https://www.youtube.com/watch?v=y6Xs-M5pOVo&feature=youtu.be

Run it in the simulator and use keyboard arrow keys to adjust ‘wind’.

@RoamingGamer, thank you for the sample code. I’ve played with it the past two days and, though I ended up not using it exactly, it provided me with different ideas on how to accomplish the behavior I wanted while also helping me to see a few variables I should have been paying attention to (e.g., gravityScale and xForce).  For the record, I went with a pivot joint from the center of the balloon to the center of the basket and placed distance joints around it on the balloon, which more or less worked as “walls.”  Here’re the snippets of code for the joint creation for those interested:

[lua]

local balloon = display.newCircle(0,0,100)

physics.addBody(balloon,{radius = 100, isSleepingAllowed=false, gravityScale=-2.5, linearDamping=1, angularDamping=1})

local basket = display.newRoundedRect(0, 150, 50, 40, 10 )

physics.addBody(basket)

basket.density = 100

local leftJoint  = physics.newJoint( “distance”,balloon, basket, -30, balloon.height*.5, -basket.width*.5,-basket.height*.5)

local rightJoint  = physics.newJoint(“distance”,balloon, basket, 30, balloon.height*.5, basket.width*.5,-basket.height*.5)

leftJoint.dampingRatio = .9

rightJoint.dampingRatio = .9

leftJoint.frequency =  2

rightJoint.frequency = 2

local centerJoint = physics.newJoint(“pivot”,balloon, basket, 0,0)

centerJoint.isLimitEnabled = true

centerJoint:setRotationLimits(-5,5)

[/lua]

Peter,

I’m glad you got something working in the way you want it to.

Cheers,

Ed

I did a hot air balloon experiment some time ago.  I’m not sure if it will help, but you can see the code here:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/experiments/003_hotAirBalloon.zip

https://www.youtube.com/watch?v=y6Xs-M5pOVo&feature=youtu.be

Run it in the simulator and use keyboard arrow keys to adjust ‘wind’.

@RoamingGamer, thank you for the sample code. I’ve played with it the past two days and, though I ended up not using it exactly, it provided me with different ideas on how to accomplish the behavior I wanted while also helping me to see a few variables I should have been paying attention to (e.g., gravityScale and xForce).  For the record, I went with a pivot joint from the center of the balloon to the center of the basket and placed distance joints around it on the balloon, which more or less worked as “walls.”  Here’re the snippets of code for the joint creation for those interested:

[lua]

local balloon = display.newCircle(0,0,100)

physics.addBody(balloon,{radius = 100, isSleepingAllowed=false, gravityScale=-2.5, linearDamping=1, angularDamping=1})

local basket = display.newRoundedRect(0, 150, 50, 40, 10 )

physics.addBody(basket)

basket.density = 100

local leftJoint  = physics.newJoint( “distance”,balloon, basket, -30, balloon.height*.5, -basket.width*.5,-basket.height*.5)

local rightJoint  = physics.newJoint(“distance”,balloon, basket, 30, balloon.height*.5, basket.width*.5,-basket.height*.5)

leftJoint.dampingRatio = .9

rightJoint.dampingRatio = .9

leftJoint.frequency =  2

rightJoint.frequency = 2

local centerJoint = physics.newJoint(“pivot”,balloon, basket, 0,0)

centerJoint.isLimitEnabled = true

centerJoint:setRotationLimits(-5,5)

[/lua]

Peter,

I’m glad you got something working in the way you want it to.

Cheers,

Ed