This project has moved and is read-only. For the latest updates, please go here.

Balls not bouncing!!!

Topics: Developer Forum, Project Management Forum, User Forum
May 16, 2013 at 7:15 PM
Edited May 16, 2013 at 7:42 PM
I created a fixture called Bolinha1 (Ball1), and gave it some speed by applying impulse onto it in the inicialization:

Bolinha1 = FixtureFactory.AttachCircle(TelaParaMundo(128,pixelspormetro)/2, 1f, CorpoBolinha1);
        Bolinha1.Restitution = 0.98f;
        Bolinha1.Friction = 0f;
        Bolinha1.Body.LinearDamping = 0f;
        Bolinha1.Body.FixedRotation = true;
        Bolinha1.Body.LinearDamping = 0f;                                                  
        Bolinha1.Body.AngularDamping = 0f;
        Bolinha1.Body.Inertia = 0;
        Bolinha1.Body.ApplyLinearImpulse(new Vector2(500, 0));
After That, i inicialize four edges, to delimit the screen:

for (int i = 0; i < 4; i++)
            SideBody[i] = BodyFactory.CreateBody(world);
            SideBody[i].BodyType = BodyType.Static;
            SideBody[i].Restitution = 0.95f;
            SideBody[i].Friction = 0f;
            SideBody[i].LinearDamping = 0f;


        Side[0] = FixtureFactory.AttachEdge(new Vector2(0, 0), new Vector2(0, 45), CorpoBorda[0]);
        Side[1] = FixtureFactory.AttachEdge(new Vector2(0, 45), new Vector2(80, 45), CorpoBorda[1]);
        Side[2] = FixtureFactory.AttachEdge(new Vector2(80, 45), new Vector2(80, 0), CorpoBorda[2]);
        Side[3] = FixtureFactory.AttachEdge(new Vector2(80, 0), new Vector2(0, 0), CorpoBorda[3]);

        for (int i = 0; i < 4; i++)
            Side[i].Restitution = 0.98f;
            Side[i].Friction = 0f;
            Side[i].Body.LinearDamping = 0f;
            Side[i].Body.AngularDamping = 0f;
, and then use only
        world.Step((float)gameTime.TotalGameTime.TotalMilliseconds * 0.01f);
as my update code.The point is, the ball sticks to the side, no matter which value i assign to the impulse, and if the impulse is great enough the ball "rolls" along the edge. I also tried tinkering with its density, but had no positive results. Can anyone help me??

PS: I know the impulse should be on the form mass * velocity, but i just started testing random numbers to see if there was some change
May 20, 2013 at 7:37 PM
Experiment with the friction and restitution on both bodies... Restitution controls the "bounciness" but you need friction as well.

Hope that helps,