How to ApplyForce at the bottom of the Box2D body.

Hi All,
I have a Ball and I want to apply force at the bottom of the ball every time when I tap on the screen.
I tried following code:
Code:
b2Vec2 ball_body_position = ballBody->GetPosition();
b2Vec2 ball_force_apply_pos;
ball_force_apply_pos.x = ball_body_position.x;
ball_force_apply_pos.y = ball_body_position.y - ballRadiusInMeters;
ballBody->ApplyForce(b2Vec2(0.0, 6.0), ball_force_apply_pos);


With the above code I am able to apply force to ball which is on the ground but the problem is if I tap more number of time
it appears like applying force at the top of the ball.

Even I tried following but same results.
Code:
ball_force_apply_pos.y = ball_body_position.y + ballRadiusInMeters;


Any help is really appreciated.

Thanks,
Madhu.
Looks fine to me. Perhaps the problem is your expectation of the behavior.
Erin:

Thanks for the reply.

With the code which I posted, I expected following behavior:
Ball is initially on the ground, when I tap on the screen it bounces up, when it is in the air if I tap again it should bounce on the air(it should go further up as I am applying force at the bottom). But the behavior what I am getting is, when the ball is on the air if I tap on the screen ball is coming down And it looks like force is being applied at the top of the ball.

Following is ball body creation:
Code:
CGFloat pixel_value_in_meters = [[WorldManager sharedInstance] pixelValueInMeters];
         
ballSizeInMeters = ball_pixel_radius*pixel_value_in_meters;
b2World* game_world = [[WorldManager sharedInstance] gameWorld];
b2BodyDef body_def;
body_def.type = b2_dynamicBody;
body_def.position.Set(x_pos*pixel_value_in_meters, (y_pos*pixel_value_in_meters));
ballBody = game_world->CreateBody(&body_def);
b2CircleShape ball_shape_box;
ball_shape_box.m_radius = (float32)ballSizeInMeters;
b2FixtureDef fd;
fd.shape = &ball_shape_box;
fd.density = 1.0f;
fd.restitution = 0.2;
ballBody->CreateFixture(&fd);


Thanks,
Madhu.
If you want an immediate response to tapping, I would use an impulse instead of a force.

I'm still stuck on this:
kmadhukishore wrote:
it looks like force is being applied at the top of the ball


How can you tell? Is the ball spinning in an unexpected way?
Quote:
I would use an impulse instead of a force.

I will try this.

Quote:
kmadhukishore wrote:it looks like force is being applied at the top of the ball
How can you tell? Is the ball spinning in an unexpected way?

It looks just like a basket ball, when we play basket ball we continuously hit at the top of the ball, so it keeps on bouncing between ground and our palm.
So it appears that the force reverses direction?
yeah exactly 🙁
Any idea why it is so??
Perhaps it is just gravity. Try making a testbed example that shows the problem.
Erin:

I made a test bed to simulate the problem in XCode, please find the project attached to this post.

Thanks,
Madhu.
That doesn't help me much. Have you tried running the Box2D testbed? It is easy to add new tests to it. You should be able to compile and run it in XCode.

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