Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Apparent bug in distance joint (box2D) — Gideros Forum

Apparent bug in distance joint (box2D)

john26john26 Maintainer
edited July 2013 in General questions
The following test code shows two bodies connected by a distance joint. I have set the damping ratio to zero so expected the bodies to continue to oscillate. However, they soon stop moving indicating friction is still present in the joint
require("box2d")
 
world=b2.World.new(0,0)
 
w=320
h=480
 
length0=100
 
atom1=world:createBody({type=b2.DYNAMIC_BODY, position={x=w/2,y=h/2}, linearVelocity={x=0,y=-50}})
atom2=world:createBody({type=b2.DYNAMIC_BODY, position={x=w/2,y=h/2+length0}, linearVelocity={x=0,y=50}})
 
shape=b2.CircleShape.new(0,0,20)
atom1:createFixture({shape=shape})
atom2:createFixture({shape=shape})
 
jointDef={type=b2.DISTANCE_JOINT, bodyA=atom1, bodyB=atom2, localAnchorA={x=0,y=0}, localAnchorB={x=0,y=0}, length=length0}
 
jointDef.frequencyHz=5
jointDef.dampingRatio=0               -- should be frinctionless
jointDef.collideConnected=false
 
joint=world:createJoint(jointDef)
 
local debugDraw = b2.DebugDraw.new()
world:setDebugDraw(debugDraw)
debugDraw:setFlags(b2.DebugDraw.SHAPE_BIT + b2.DebugDraw.JOINT_BIT)
stage:addChild(debugDraw)
 
function update()
  world:step(1/60,8,3)
end
 
stage:addEventListener(Event.ENTER_FRAME, update)
Is there any way to make a frictionless joint?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    @john26 pardon my knowledge of physics, but I think that frequency has something to do with that.
    By box2d docs, it's a The mass-spring-damper frequency in Hertz.
    As in it's a damper frequency and not (here comes the physics term) jumping frequency.
    I currently don't know if something like that can be achieved by joints only, but it should be possible by either adjusting restitution of objects (if they can collide), or controlling their linear velocity
  • john26john26 Maintainer
    This seems to be a problem with Box2D. Here is a description from the man himself (Errin Catto)

    http://www.box2d.org/forum/viewtopic.php?f=3&t=7017

    It seems Box2d has an update algorithm which automatically adds friction to springs even ones the user specifies as having zero damping. In the above link there is PDF linked which gives more details. I'm a bit disappointed to be honest, I thought Box2d's output would be physically realistic. Catto's reason is the algorithm ensures stability but you also have to solve the correct physics!

    But it occurred to me that now Catto knows the problem he may have fixed it. So what version of Box2D is Gideros running? Are you keeping up with new versions?

Sign In or Register to comment.