0

I have a dynamic platform which is moved by the keyboard. Think brick breaker games. I want it to reflect other dynamic objects that hit it, but I don't want it to get knocked all over the place. How do I do that?

Appreciate the help. Thanks.

Davina Leong
  • 737
  • 2
  • 11
  • 28
  • Large mass for platform? Shall it be pushed by heavy objects slightly, it might even look interesting. – alxx Jul 03 '12 at 06:14

1 Answers1

0

You can make the platform a kinematic body. Set the type to b2_kinematicBody in the body definition before you create it, or do body->SetType(b2_kinematicBody) after you create it.

Kinematic bodies do not respond to forces or impulses, so you will need to use SetLinearVelocity to move it. They also do not collide with static bodies so if you have static-body walls at the side of your playing area, the platform will be able to move right through them - you'll have to check the position each time step to see if the platform should stop.

iforce2d
  • 8,194
  • 3
  • 29
  • 40
  • But how do I move it with a keyboard? I need the platform controllable. Normally for dynamic objects, I would apply force when a key pressed. – Davina Leong Jul 04 '12 at 15:22
  • When the left key is down, set the linear velocity to move it left, eg. SetLinearVelocity( b2Vec2(-1,0) ) and when the right key is down do SetLinearVelocity( b2Vec2(1,0) ). When both keys or no keys are down, do SetLinearVelocity( b2Vec2(0,0) ). – iforce2d Jul 04 '12 at 15:33