There seems to be various areas in our game where we need to have a joint that allows two bodies to rotate but to have a stretching limit of the joint. Rope for example falls apart under heavy load. A trapdoor that needs to rotate open without being able to place an object on it and have it stretch apart at the joint. We are using b2RevoluteJoint's for most cases as they seem to be the ones most suited. Is it possible to limit how far they can stretch or are we using the wrong type of joints?
Joint stretch limit
General DiscussionAre you saying that you want the joint to break under load? Or are you saying the joint is stretching unintentionally? Right now the revolute joint is quite solid by itself. Chains of joints may still stretch.
I don't want the joints to break. A trapdoor for example is simply a box with it's centre of mass to one side and a single revolute joint at it's end. At the moment the main character (a circle) rolling up this trapdoor begins to stretch at the revolute joint and keep stretching as you roll up and down it.
Ah this might be a mass ratio problem. Is the mass of the character much higher than the mass of the door? Are you moving the character by through forces/impulses alone?
I have had quite a fiddle with this problem and really struggled to find a solution.
Originally (a couple of box2d SVN updates ago) this was working perfectly. The trapdoor was solid and could withstand several objects on it along with the player.
In the level, we have a trapdoor that is closed and an enemy (large box) walks across it with no affect on the trapdoor. But... if the player (smaller circle) stands on it, the trapdoor stretches at the revolute joints and 'gives up the ghost'.
The only thing that we are doing is using a higher gravity than normal (and have been for 5 months). The gravity is set to 40.0 and has been fine prior. (the gravity is set high to allow a more immediate jumping arc and to allow other objects to fall quicker).
I wonder if this is an issue with mass on circles?
We are using the latest Box2d SVN (116) and have only had this problem very recently. Any help or suggestions would be wonderful.
Originally (a couple of box2d SVN updates ago) this was working perfectly. The trapdoor was solid and could withstand several objects on it along with the player.
In the level, we have a trapdoor that is closed and an enemy (large box) walks across it with no affect on the trapdoor. But... if the player (smaller circle) stands on it, the trapdoor stretches at the revolute joints and 'gives up the ghost'.
The only thing that we are doing is using a higher gravity than normal (and have been for 5 months). The gravity is set to 40.0 and has been fine prior. (the gravity is set high to allow a more immediate jumping arc and to allow other objects to fall quicker).
I wonder if this is an issue with mass on circles?
We are using the latest Box2d SVN (116) and have only had this problem very recently. Any help or suggestions would be wonderful.
After some rolling back I've discovered that r113 introduces the problem. We have a swing which is short "rope" made using revolute joints connected to a box. In r112 or earlier our player (circle) can jump on this no problems, the joints only give slightly. In r113 the rope stretches apart like the player has become very heavy. My guess is a mass problem with circles or something to do with revolute joints. There have been other strange goings on since this release as described earlier and things like boxes that were stacked up fine previously now fall off a platform. I understand it's an unstable revision but the latest has the same problem. We will stay with r112 for now. If you find a bug and fix it please let us know so we can update again.
Couple of other notes: b2LoopShape uses memcpy so it needs to #include <string.h> and b2ContractSolver has "Unused variable 'cp'" with the line "b2ManifoldPoint* cp = manifold->points + j;"
Couple of other notes: b2LoopShape uses memcpy so it needs to #include <string.h> and b2ContractSolver has "Unused variable 'cp'" with the line "b2ManifoldPoint* cp = manifold->points + j;"
Any help to recreate this in the testbed would be appreciated. Also filing an issue would be a big help:
http://code.google.com/p/box2d/issues/list
http://code.google.com/p/box2d/issues/list
Okay I can replicate this bug in the Testbed by making a little swing.
As you can see from the snapshots in r112 the swing is stable, but in r113+ it falls to pieces.
Code:
/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BUG_H
#define BUG_H
class Bug : public Test
{
public:
Bug()
{
b2Body* ground = NULL;
{
b2BodyDef bd;
ground = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
ground->CreateFixture(&shape, 0.0f);
}
// Platform
{
b2BodyDef bd;
bd.position.Set(0.0f, 20.0f);
b2Body* body = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(8.0f, 0.5f);
m_platform = body->CreateFixture(&shape, 0.0f);
}
// Swing
{
b2BodyDef bd;
bd.position.Set(0.0f, 13.0f);
bd.type = b2_dynamicBody;
b2Body* body = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(8.0f, 0.5f);
m_swing = body->CreateFixture(&shape, 0.0f);
}
// Actor
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(0.0f, 18.0f);
bd.fixedRotation = false;
bd.allowSleep = false;
bd.bullet = true;
bd.angularDamping = 0.5f;
bd.linearDamping = 0.0f;
b2Body* body = m_world->CreateBody(&bd);
m_radius = 2.4f;
b2CircleShape shape;
shape.m_radius = m_radius;
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 1.0f;
fd.friction = 1.0f;
fd.restitution = 0.35f;
fd.isSensor = false;
m_character = body->CreateFixture(&fd);
body->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
}
{
b2PolygonShape shape;
shape.SetAsBox(0.125f, 0.6f);
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 20.0f;
fd.friction = 0.2f;
b2RevoluteJointDef jd;
jd.collideConnected = false;
const float32 y = 19.9f;
b2Body* prevBody = m_platform->GetBody();
for (int32 i = 0; i < 7; ++i)
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(-4.0f, y - i);
b2Body* body = m_world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(-4.0f, y - i);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
b2Vec2 anchor(-4.0f, y - 7);
jd.Initialize(prevBody, m_swing->GetBody(), anchor);
m_world->CreateJoint(&jd);
prevBody = m_platform->GetBody();
for (int32 i = 0; i < 7; ++i)
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(4.0f, y - i);
b2Body* body = m_world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(4.0f, y - i);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
anchor = b2Vec2(4.0f, y - 7);
jd.Initialize(prevBody, m_swing->GetBody(), anchor);
m_world->CreateJoint(&jd);
}
}
static Test* Create()
{
return new Bug;
}
float32 m_radius;
b2Fixture* m_platform;
b2Fixture* m_swing;
b2Fixture* m_character;
};
#endif
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BUG_H
#define BUG_H
class Bug : public Test
{
public:
Bug()
{
b2Body* ground = NULL;
{
b2BodyDef bd;
ground = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
ground->CreateFixture(&shape, 0.0f);
}
// Platform
{
b2BodyDef bd;
bd.position.Set(0.0f, 20.0f);
b2Body* body = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(8.0f, 0.5f);
m_platform = body->CreateFixture(&shape, 0.0f);
}
// Swing
{
b2BodyDef bd;
bd.position.Set(0.0f, 13.0f);
bd.type = b2_dynamicBody;
b2Body* body = m_world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(8.0f, 0.5f);
m_swing = body->CreateFixture(&shape, 0.0f);
}
// Actor
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(0.0f, 18.0f);
bd.fixedRotation = false;
bd.allowSleep = false;
bd.bullet = true;
bd.angularDamping = 0.5f;
bd.linearDamping = 0.0f;
b2Body* body = m_world->CreateBody(&bd);
m_radius = 2.4f;
b2CircleShape shape;
shape.m_radius = m_radius;
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 1.0f;
fd.friction = 1.0f;
fd.restitution = 0.35f;
fd.isSensor = false;
m_character = body->CreateFixture(&fd);
body->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
}
{
b2PolygonShape shape;
shape.SetAsBox(0.125f, 0.6f);
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 20.0f;
fd.friction = 0.2f;
b2RevoluteJointDef jd;
jd.collideConnected = false;
const float32 y = 19.9f;
b2Body* prevBody = m_platform->GetBody();
for (int32 i = 0; i < 7; ++i)
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(-4.0f, y - i);
b2Body* body = m_world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(-4.0f, y - i);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
b2Vec2 anchor(-4.0f, y - 7);
jd.Initialize(prevBody, m_swing->GetBody(), anchor);
m_world->CreateJoint(&jd);
prevBody = m_platform->GetBody();
for (int32 i = 0; i < 7; ++i)
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(4.0f, y - i);
b2Body* body = m_world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(4.0f, y - i);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
anchor = b2Vec2(4.0f, y - 7);
jd.Initialize(prevBody, m_swing->GetBody(), anchor);
m_world->CreateJoint(&jd);
}
}
static Test* Create()
{
return new Bug;
}
float32 m_radius;
b2Fixture* m_platform;
b2Fixture* m_swing;
b2Fixture* m_character;
};
#endif
As you can see from the snapshots in r112 the swing is stable, but in r113+ it falls to pieces.
Not a bug. You set the density on the dynamic swing body to zero.
Erin Catto wrote:
Not a bug. You set the density on the dynamic swing body to zero.
If I set the density of the swing body to 0.3f and you roll around it still falls apart and you can slip between the revolute joints. If this is expected behaviour then why has this only started happening since r113?
Original thread: https://box2d.org/forum/viewtopic.php?t=5156