Allowing objects to move upside down

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:

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());
}


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]);
   }
}


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.
Can't you just apply a force upwards to your player body? Perhaps you could say why you need to use a collision normal at all... is he gonna walk on walls and stuff as well?

Just one thing I could mention at this stage is that you would be better off with ApplyLinearForce than using impulses.
Our platforms can be any shape so the force needs to be appied to any angle. Hence the need to use a contact normal.

I am use ApplyLinearImpulse for this but the ApplyForce works fine for cancelling out gravity.
Any ideas?
I believe the normal in the manifold is just the shortest direction to move the fixtures to stop them from overlapping, so it's not always what you want. Likewise the contacts points may not always be what you want either - search the manual for section "4.8 Contact Manifolds", you can see a visual representation.

I'm still not clear about whether you want to have your character walking at any old angle which would allow him to walk on walls, or just vertically reversed gravity so he can walk on the ceiling, as the title of the thread ('upside down') implies . If you only need him to walk on the ceiling, just apply your gravity-negating force again vertically straight upwards. But for walking on walls... um, not sure what you could do there... 🙂
I guess I should have used the phrase 'stick to walls' instead of 'upside down'.
I also forgot to mention the 'object' is actually the shape of a circle.
hmm... the best idea I can think of right now is to cover the walls/ceiling with sensors, defining regions of 'gravity'. Some might pull the character up, some might pull him sideways etc. depending on which sensors he is currently in contact with the direction will vary. Could be a lot of setting up to do though...

Original thread: https://box2d.org/forum/viewtopic.php?t=5864