I have been reading about allowing objects to move upside down despite having gravity applied to the world. From what I've been reading the best way to do this is to negate gravity and then apply a force using contact normals.
I now have the following function written to negate gravity:
Now I am trying to apply a force so the object can move upside down
This method doesn't seem to be working. What am I doing wrong?
EDIT: Forgot to mention that the PreSolve method here is passed parameters were fixtureA is always the Object's fixture.
I now have the following function written to negate gravity:
Code:
void Actor::NegateGravity(b2Fixture* fixture)
{
b2Body* body = fixture->GetBody();
body->ApplyForce(b2Vec2(-g_gravity->x * body->GetMass(), -g_gravity->y * body->GetMass()), body->GetWorldCenter());
}
{
b2Body* body = fixture->GetBody();
body->ApplyForce(b2Vec2(-g_gravity->x * body->GetMass(), -g_gravity->y * body->GetMass()), body->GetWorldCenter());
}
Now I am trying to apply a force so the object can move upside down
Code:
void Object::OnPreSolve(b2Contact* contact, b2Fixture* fixtureA, b2Fixture* fixtureB, Actor* actor)
{
b2Body* body = fixtureA->GetBody();
b2Manifold* manifold = contact->GetManifold();
int pointCount = manifold->pointCount;
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
b2Vec2 normal = worldManifold.normal;
for(int i=0; i<pointCount; i++)
{
normal = -normal;
normal *= g_gravity->y;
body->ApplyLinearImpulse(normal, worldManifold.points[i]);
}
}
{
b2Body* body = fixtureA->GetBody();
b2Manifold* manifold = contact->GetManifold();
int pointCount = manifold->pointCount;
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
b2Vec2 normal = worldManifold.normal;
for(int i=0; i<pointCount; i++)
{
normal = -normal;
normal *= g_gravity->y;
body->ApplyLinearImpulse(normal, worldManifold.points[i]);
}
}
This method doesn't seem to be working. What am I doing wrong?
EDIT: Forgot to mention that the PreSolve method here is passed parameters were fixtureA is always the Object's fixture.