0
votes

I would like to make brick breaker like game but with bricks that react to physics. I set world to have 0 gravity and bricks have big linear and angular dumping set.

But I have problem with ball. I would like my ball to have the same constant speed all the time. Even after colliding with bricks, walls and paddles (Yes, I have 2 of them). I know that this is not how physics work.

But is there any way to make ball not loose speed on contact with some bodies? And make the ball bounce from bricks instantly without loosing it's energy but applying force to them (bricks)?

1

1 Answers

0
votes

I was looking for that too but in AS3 - I did find what I wanted for c++. After giving it a read I think below is what you intended, to move an object at a constant speed using Box2D physics. I'll post the link too although it's not good practice to answer questions with links as they may break in the future. Constant Speed

  b2Vec2 vel = body->GetLinearVelocity();
    float desiredVel = 0;
    switch ( moveState )
    {
      case MS_LEFT:  desiredVel = -5; break;
      case MS_STOP:  desiredVel =  0; break;
      case MS_RIGHT: desiredVel =  5; break;
    }
    float velChange = desiredVel - vel.x;
    float impulse = body->GetMass() * velChange; //disregard time factor
    body->ApplyLinearImpulse( b2Vec2(impulse,0), body->GetWorldCenter() );