UIKit+Box2D based air hockey game

I'm developing an air hockey game for iOS based on UIKit and Box2D. I managed to model the world (table limits, puck and handles), and move the handles around their respective play areas, however, I'm still unable to cause the puck (ball) to move around the table when I hit it with the handle (it simply gets displaced a little). I guess this is because the mallet does not have a velocity vector, I'm simply setting its position every time its touchesMoved method gets called.

Code: Select all

    CGFloat Xm = px2m(pos.x);
    CGFloat Ym = px2m(480.0 - pos.y);   
    malletBody->SetTransform(b2Vec2(Xm, Ym), 0);


I'm a complete Box2D newbie so I'll appreciate any pointer you can give me about how I can get the expected result.
Sorry for my broken English!

edit: (px2m is a function that translates pixel coordinates to Box2D coordinate system).
You could SetLinearVelocity of the body so that it will cover the necessary distance to the touch point in one time step. eg. if the body needs to move (2,3) units to get to the desired location and your timestep is 60Hz you could SetLinearVelocity(120,180) for one time step. In the next time step you would of course have to set the velocity back to zero to stop it flying of into the distance.
Thank you so much! Yesterday I wasted two hours trying to understand how this worked, but with your help I fixed it in minutes! 😀

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