First post and first topic!
Hi.
I am creating a game with a group of fellow students.
The game machanic is quite easy. You control a softbody blob that can
stick to walls. (similar to the game Gish)
The problem i am having right now is making the said ball stick to
said walls. I am trying to take the contact point of two bodies and
am trying to place a distance joint between them. But i seem to be
unable to find a proper local position for my anchors. The way i do
it now creates strange behaviour (throwing the ball to different directions)
So my question is: "How do i get the actual collision point of two colliding
bodies" Preferable in their own local space.
Hi.
I am creating a game with a group of fellow students.
The game machanic is quite easy. You control a softbody blob that can
stick to walls. (similar to the game Gish)
The problem i am having right now is making the said ball stick to
said walls. I am trying to take the contact point of two bodies and
am trying to place a distance joint between them. But i seem to be
unable to find a proper local position for my anchors. The way i do
it now creates strange behaviour (throwing the ball to different directions)
So my question is: "How do i get the actual collision point of two colliding
bodies" Preferable in their own local space.
Code:
for (int i = 0; i < P_BALLS_COUNT; i++)
{
for (b2ContactEdge* ce = mBodies[i]->GetContactList(); ce; ce = ce->next)
{
if ((i < P_BALLS_PER && mBools[PB_MOUSE_DOWN_LEFT_PREV]) ||
(i >= P_BALLS_PER && mBools[PB_MOUSE_DOWN_RIGHT_PREV]))
{
b2Contact* c = ce->contact;
b2DistanceJointDef jd;
jd.frequencyHz = 6.0f;
jd.dampingRatio = 0.9f;
jd.bodyA = c->GetFixtureA()->GetBody();
jd.bodyB = c->GetFixtureB()->GetBody();
jd.localAnchorA = c->GetManifold()->localPoint;
jd.localAnchorB = c->GetManifold()->localPoint;
jd.length = 0.01;
jd.collideConnected = true;
jd.bodyA = c->GetFixtureA()->GetBody();
jd.bodyB = c->GetFixtureB()->GetBody();
if (mConnectionJoints[i] != 0)
{
mPhysics->GetWorld()->DestroyJoint(mConnectionJoints[i]);
mConnectionJoints[i] = 0;
}
mConnectionJoints[i] = mPhysics->GetWorld()->CreateJoint(&jd);
}
else
{
if (mConnectionJoints[i] != 0)
{
mPhysics->GetWorld()->DestroyJoint(mConnectionJoints[i]);
mConnectionJoints[i] = 0;
}
}
}
}
{
for (b2ContactEdge* ce = mBodies[i]->GetContactList(); ce; ce = ce->next)
{
if ((i < P_BALLS_PER && mBools[PB_MOUSE_DOWN_LEFT_PREV]) ||
(i >= P_BALLS_PER && mBools[PB_MOUSE_DOWN_RIGHT_PREV]))
{
b2Contact* c = ce->contact;
b2DistanceJointDef jd;
jd.frequencyHz = 6.0f;
jd.dampingRatio = 0.9f;
jd.bodyA = c->GetFixtureA()->GetBody();
jd.bodyB = c->GetFixtureB()->GetBody();
jd.localAnchorA = c->GetManifold()->localPoint;
jd.localAnchorB = c->GetManifold()->localPoint;
jd.length = 0.01;
jd.collideConnected = true;
jd.bodyA = c->GetFixtureA()->GetBody();
jd.bodyB = c->GetFixtureB()->GetBody();
if (mConnectionJoints[i] != 0)
{
mPhysics->GetWorld()->DestroyJoint(mConnectionJoints[i]);
mConnectionJoints[i] = 0;
}
mConnectionJoints[i] = mPhysics->GetWorld()->CreateJoint(&jd);
}
else
{
if (mConnectionJoints[i] != 0)
{
mPhysics->GetWorld()->DestroyJoint(mConnectionJoints[i]);
mConnectionJoints[i] = 0;
}
}
}
}