How to apply momentum on a body in Box2d in iphone Xcode

hello i decided to join box2d i m new one in Game programming. i have one issue how can i apply momentum on a body let me clarify the issue like in pinball game suppose i have a stick if ball touch that stick then it gets speed as i did but this is not what i want, what i want when i move the stick if it touch the ball the ball should get the real momentum like in baseball Or in Cricket ..
Thanks
Umer Sufyan
Let the pin be a static body and have restitution higher than 1. That'll let any object that touch the pin get higher energy than before it hits. Having the value 1 will exactly reflect the balls momentum, and lower will absorb some of the energy.

However, I wonder if you'll be able to do anything in programming if you can't even master punctuation in common English. Your post is difficult to read, and honestly a bit hard to take seriously.
Thank you for your good reply i m weak in English 😢 and trying to overcome this problem.
Thanks it did work.
Indeed it does work but here is a one problem with that way , Actually i want to achieve the speed with the movement of stick .
Suppose a scenario , In pinball game if you notice the stick doest not apply any force on ball when the stick is in rest but when we move the stick it applies or exerts a force on ball as in real world we see, Can you give me some guide line regarding this.
umersufyan wrote:
Indeed it does work but here is a one problem with that way , Actually i want to achieve the speed with the movement of stick .
Suppose a scenario , In pinball game if you notice the stick doest not apply any force on ball when the stick is in rest but when we move the stick it applies or exerts a force on ball as in real world we see, Can you give me some guide line regarding this.

Let me see if I understand you correctly. You want something like a baseball bat to hit a ball with high force so that the ball gets a high velocity? If so, the pinball pin I explained earlier will not do too well.

It's just basic mechanical physics. Heavy bat hits a light ball at high speed = the ball flies off. You should probably have a high restitution of about 0.8 or so on the ball. Game balls are usually designed to absorb a lot of energy to fly as far as possible.

  • The ball should be dynamic and light weight, high restitution.
  • The bat should also be dynamic, but with some more mass. Just a rectangle in shape.
  • Put a motor joint in one end of the bat to make the bat rotate towards the ball and give it a lot of torque.

Read some in the manual about the motor joints: http://box2d.org/manual.html#_Toc258082974
thanks for you valuable suggestion Actually i want to make a pinball game where the stick (i think should be static) so it is(according to my view) . Should i change it to dynamic and apply a motor to it so that when stick hits the ball it should move like in pinball game...
Any Ways Thanks 🙂
I'm really confused about what you're trying to achieve.

If you mean the non moving pins and other things on the top of the playfield, then use a static body with high restitution depending on the effect you wish to get. Some pins are just metal with low restitution (<1), some are rubber bands that shoots the ball away which would be a very high (>1) restitution.

If you mean the flipper pads at the bottom that the player controls to flip the ball upwards, then use a dynamic body with a motor joint. Flippers swing to send the ball away, so they must be dynamic.

Static bodies are not meant to be moved around. If they are, you may get unexpected results in the physics because they have infinite mass and doesn't have velocities
Moving => use dynamic body
Stationary, unmovable => use static body
hello i want to make a pinball game see in the picture http://itunes.apple.com/us/app/pinball- ... 92836?mt=8
Sticks are in yellow color . i m looking for a way how to get the real impulse of force when the ball collides the moving stick, You said that i can achieve this by applying torque on my stick and it should be dynamic body am i right ? i do hope it should be clear now.
Yes, those yellow things are called "flippers", not sticks. You should make these dynamic and with a motor joint to turn them, just like a real pinball game.

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