Make a body not to fall [when a body jumps on it]

Hi everyone !

I've got a little bit problem in my app using box2D.
I want to get one of my bodies not to fall, never. But I don't know how to get that…

I tried to apply on it a force which was exactly the opposite of the force of gravity but if the density of it is too low, the body flies up, and if it is too high, it falls down. I also managed to get a value which would give the effect I needed, but 7.6 is too low and 7.61 is too high…

Well, after that I tried with SetTransform, it works but the collisions with the character are pretty weird… (as my character is thrown away when it tries to get on the body).

So do you know what can I do ? Thanks 😀
Disable gravity and apply gravity only to bodies that need it.
Is that the only way ?

By doing so, I will need to apply gravity onto every other body…

So you mean manually ? With an ApplyForce each frame ?
Sheeft wrote:
Is that the only way ?

By doing so, I will need to apply gravity onto every other body…

So you mean manually ? With an ApplyForce each frame ?

Yes, I think that's the idea - just apply the force manually for each body that needs it.

I believe the question of 'per-body gravity' has come up before, and the gist of the thread was that if this is something a user needs, he or she should just handle any applied gravity forces manually. (The rationale behind this being, perhaps, that implementing this in the library would add extra overhead and complexity for a feature that may only be needed occasionally, and which can easily be implemented manually if needed.)
Okay, thanks, I think I will create an ApplyGravity function to do that.
So if I put a gravity vector of (0;5) at the beginning… Now I just need to apply the same vector each frame to all of my bodies but the one for which i don't want any… Right ?
Quote:
So if I put a gravity vector of (0;5) at the beginning… Now I just need to apply the same vector each frame to all of my bodies but the one for which i don't want any… Right ?

Right, that's the basic idea.
Well, okay, but a problem remains now…
If my character jump onto one of the none-gravity-affected body, then it makes it going down.
In fact, I would like to have my body dynamic but only on the left and on the right…

How can I do that ?
Thanks.

EDIT : If you want the whole plot, what I'm trying to do is a platform which moves from left to right as in a lot of games…
But actually, if my character touch them, they're thrown in the direction of the character but it still moves as I ask.
I want to avoid here, the effect of the other bodies, but I would like it to have effects onto the other bodies…

EDIT : How do you avoid it to fall at all, whatever the forces ?
Wait... ever heard of static bodies?
If that's not what you want - you can try to stick your body with a joint to world body.

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