I am having all kinds of problems with my joints. Even pivot joints. I know there is a thread on joint elasticity and even when doing that I still have problems. I have a couple pivot joints anchored to another dynamic body and they keep getting all glitchy looking and stretching. I can reduce it some by reducing the density but its still there.
Setting my physics scale to 60 instead of 30 helps, but increasing the iterations only helps with the stretching of the joints and not the jerkyness when it collides.
I had some other dynamic objects resting on top of this object with the joints and they were evidently to heavy as they were pushing the joint object down and making it unstable.
Anyway, I was shocked when I changed the fps from 30 to 60. It instantly fixed everything. Even without changing the density of the dynamic objects that were smashing my joint object it still worked perfectly. No more glitching and no more stretching of the joints.
Why did it do this? Is it because it is now updating everything twice as often and makes the collisions more stable? Is it like the timestep in AS3? If not, can I change the equivalent to the timestep in corona? The number one recommendation on box2d forums when you have these types of problems is to change your timestep.
It says this in the box2d manual.
“Continuous collision is processed sequentially. In a time of impact event, the body is moved back and held there for the rest of the time step. This may make fast moving objects appear to move in a non-smooth manner.”
I wonder if this is making it non smooth looking. From my understanding though corona doesn’t use continuous collision unless isBullet is true. But even with or without isBullet, it still looks bad.
You may be thinking why am I complaining if changing to 60fps fixed everything? Well I can’t use 60fps because my game will not be able to run at 60fps on older devices and probably even current devices. I have to use 30fps so the game will run at full speed unless it drops below 30fps on the device.
Here is the sample code I used in the piston problem, but if you run this at 30fps and then change the fps to 60 in your config.lua you can see that it strengthens the piston joint. The big box seems to be falling at the same speed so I don’t think it affects gravity, but the medium box does not go down as far on impact.
In my actual game I use several pivot joints (or piston joints if I can get them working properly) on objects and they stretch and glitch like crazy even with low density until I change the fps to 60.
local physics = require("physics")
physics.start()
physics.setDrawMode("debug")
display.setStatusBar( display.HiddenStatusBar )
local function startDrag( event )
local t = event.target
local phase = event.phase
if "began" == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
event.target.bodyType = "kinematic"
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
elseif t.isFocus then
if "moved" == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
event.target.bodyType = "dynamic"
end
end
return true
end
local bigBlock = display.newRect( 0, 0, 128, 128 )
bigBlock.x = 160; bigBlock.y = 0
physics.addBody( bigBlock, { density=5.0, friction=0.4, bounce=0.2 } )
local anchor = display.newRect( 0, 0, 32, 32 )
anchor.x = 160; anchor.y = 400
physics.addBody( anchor, "static" )
local block = display.newRect( 0, 0, 64, 64 )
block.x = 160; block.y = 300
physics.addBody( block, { density=3.0, friction=0.4, bounce=0.2 } )
bigBlock:addEventListener( "touch", startDrag )
block:addEventListener( "touch", startDrag )
myJoint = physics.newJoint( "piston", block, anchor, anchor.x, anchor.y, 0,5 )
myJoint.isLimitEnabled = true
myJoint:setLimits(1,1)
[import]uid: 10243 topic_id: 6008 reply_id: 306008[/import]