Trivial dummy no gravity - linear and constant acceleration

Hi all,

I've been searching and looking most everywhere, but I still stuck. So here I am trying to get some help from the community.

I have this basic example of bouncing ball in a box. I am using javascript Box2D port.
What I want to do is quiete simple :

1. Ball with different radius : DONE
2. Ball with Different position at startup : DONE
3. Ball with different linear velocity at startup : NOT DONE
4. Ball keep bouncing at the same speed what ever happen : NOT DONE

So the point 4 is my main concern. What I want is something with no physics behavior. My problem in the example is that if two balls get in contact and in oposite direction the bigger ball will decelerate and so... sometimes the biggest ball get stuck.
Please check out here :

http://bit.ly/d3fI5V

Thanks a lot in advance,

G
You should be able to use SetLinearVelocity to adjust the speed of the ball if it becomes too slow or fast.
This is also what you should use to set a starting velocity for an object too.
How are you currently setting the speed of your objects?
Hi !
Thanks for the reply, I do this in the init :

Code:
for (var worldbody = world.GetBodyList(); worldbody; worldbody = worldbody.GetNext()) {
          var force = new b2Vec2(2000,randomBorn(200,300));

         worldbody.SetAwake(true);
         //worldbody.ApplyForce(force,worldbody.GetWorldCenter());
         worldbody.SetLinearVelocity(force);
         //worldbody.ApplyImpulse(force,worldbody.GetWorldCenter());

        }


So from what you said I have to check the Velocity on x + y caluclate the avarage velocity and then apply an impulse if it is too slow ? It looks ackward to me, doesn't it exist any propoerties to avoid this, like elasticity or I do not know masses ? or anything else ?
You can set the restitution of fixtures to 1, that is supposed to preserve all the energy in collisions, but it does not preserve the speed of them after the collision. For example even if a light object and a heavy object collide head-on with 100% energy preserved, the heavy object will end up going in the same direction it started, but a little bit slower, and the light object will bounce back the way it came, but faster. If you get the speeds just right, the heavy object could stop completely, but energy is still preserved.

It sounds like this is exactly what you are trying to avoid right? However this is correct physical behavior which is what box2d tries to give you. To make it non-physics like you say, you will have to do something extra yourself. Don't worry, this one is quite easy:
Code:
b2Vec2 currentDirection = body->GetLinearVelocity();
currentDirection.Normalize();
body->SetLinearVelocity( desiredSpeed * currentDirection );
Also, Box2d is not perfectly conservative due to approximations in the algorithms used. Of course, the errors tend to cause energy gain, not loss.
Storyyeller wrote:
Also, Box2d is not perfectly conservative due to approximations in the algorithms used. Of course, the errors tend to cause energy gain, not loss.


Often the opposite is true. For example, pendulums tend to come to rest without any explicit damping. If you have an example of unbounded energy gain, please file an issue here: http://code.google.com/p/box2d/issues/list

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