Combine SetLinearVelocity with ApplyForce

So, i've started making a game which is basically about catching falling boxes with a small platform. The setup is as follow and looks like the screenshot attached:

http://d.pr/i/M9C0

The blue platform in the bottom is a kinematic body which is moved by setting SetLinearVelocity (since it doesn't support force/impulse) every tick depending on mouse position, moving from side to side of the screen preventing the falling boxes to reach the bottom. The red dynamic boxes fall from the top without any forces except gravity. When contact between the platform and a box is triggered the current velocity of the platform is applied to the box, making sure the box moves along with the platform.

Some code:

Code: Select all

var p:Number = _platformBody.GetLinearVelocity().x;

while (i--){
  var item:b2Body = _items[i];
  var vel:b2Vec2 = item.GetLinearVelocity();
  if( item.GetUserData().contact ){    
    item.SetLinearVelocity(new b2Vec2(p, vel.y) );
  }
}


This setup works but produces some funny looking results and doesn't feel like the best way of doing this. Upon collision the boxes loose there own velocity and isn't affected by the gravity (they balance on each other in strange ways instead of falling of each other). Instead I would like to apply an impulse/force to the boxes with the velocity of the platform upon collision and every tick where contact is true, making sure the boxes still keep there own velocity. I've also tried different settings when it comes to friction, density and restitution but I don't think that's the issue here. 

My question is how to convert the SetLinearVelocity into impulse/force in a way so that the falling boxes keep there own forces as well as the one from the platform.

Thanks

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