Non-unifrom gravity

Hey guys,
I have made a platform game with Box2d in cocos2dx. But the issue i am facing now is for the same amount of setlinearvelocity, i am getting non uniform gravity reactions on the body. Any idea how i can debug this? And also the velocity in the y direction i get from body->getlinearvelocity().y is zero when i move the body in 2D plane.......Any idea why this is the case?
Is there anyway to get the forces acting on a body?

Thank you
It's quite hard to tell what you're talking about here. How about a simple example to explain what you mean by a 'gravity reaction'?

"...when I move the body in the 2D plane..."
Aren't bodies always moving in the 2D plane? How are you moving it? Do you call SetLinearVelocity and then immediately after that GetLinearVelocity returns zero?
Bodies can also move in 1 direction, we call it 1D rt? For example just jumping, just moving right, just moving left. When you jump and move right, we can say 2D motion. Ya but my usage of 2D plane was inappropriate 😛

This is the thing, when i jump straight up this is what i get when i print the getlinearvelocity().y while the body is coming down.


I am falling with velocity -0.09
I am falling with velocity -0.144
I am falling with velocity -0.1764
I am falling with velocity -0.19584
I am falling with velocity -0.207504
I am falling with velocity -0.214502
I am falling with velocity -0.218701
I am falling with velocity -0.221221
I am falling with velocity -0.222733
I am falling with velocity -0.22364
I am falling with velocity -0.224184
I am falling with velocity -0.22451
I am falling with velocity -0.224706
Jump Button Release
I am falling with velocity -0.224824
I am falling with velocity -0.224894
I am falling with velocity -0.224937
I am falling with velocity -0.224962
I am falling with velocity 0


That is perfect downward acceleration

But when i am jumping as well as moving to a direction i get this

I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0
I am falling with velocity 0

In this case, the body is falling alright, but no acceleration.
By gravity reaction i meant acceleration downwards.

So my assumption is when i am keeping the buttons pressed some other force is acting on it. I want to know that...........Anyway to do that?
Ok, so how are you moving it?
I am using setLinearVelocity in a loop to make it move up. and keeping on reducing the b2vec2.y value to come to a halt at the top and from there no forces are applied. It is free fall.
And how are you making it move sideways during the jump? I'm just wondering if maybe you are using SetLinearVelocity with a value of zero for the y component.
if(is_running)
{
body->SetLinearVelocity(b2Vec2(run_power,0.0f));
}
if (is_pushup)
{
body->SetLinearVelocity(b2Vec2(run_power,jump_power));
}
This is how i do it.........
when i start pressing right or left keys 'is_running' is made 'true' and the 'run_power' is increased until it reaches a particular value. Once those keys are released, 'run_power' will be exponentially decreased to 0 and 'is_running' made 0.

in the case of jump, when jump key is pressed, a high value is given to jump which is decreased to 0 is_pushup is made 0.

So my problem is actually that when 'is_running' is true and 'is_pushup' is false, y velocity is returning 0 but the object is falling down, but without acceleration.
Is it because i am setting the y component as 0 in the 'is_running' if? Then how can the body come down?
If is_running is 0, the body works like a charm, accelerating downwards........

Hope you understand.....
kodemax
Yeah, you just need to keep the original y-velocity, to preserve the falling speed:
Code:
if ( is_running )
{
    b2Vec2 vel = GetLinearVelocity();
    vel.x = run_power; //change only horizontal value
    body->SetLinearVelocity( vel );
}
OK Thanks a lot 🙂 Everything solved now 🙂

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