This project has moved. For the latest updates, please go here.

Newbie: Help! I can’t make two bodies collide.

Topics: Developer Forum, User Forum
Feb 11, 2014 at 9:57 PM
I have 2 balls, the first cannot move the second is dropped on the first and I expect it will bounce off. What’s wrong in my code?
       //Create a World object with a normal gravity
        world = new World(new Vector2(0f, 9.82f));            

        //We create a body object and make it dynamic (movable)
        myBody = BodyFactory.CreateBody(world, new Vector2(100, 100));
        myBody.FixedRotation = true;
        myBody.BodyType = BodyType.Dynamic;
        //We create a circle shape with a radius of 0.5 meters
        circleShape = new CircleShape(0.5f, 1.0f);                                 

        //We fix the body and shape together using a Fixture object
        fixture = myBody.CreateFixture(circleShape);
        fixture.Restitution = 0.7f;
        fixture.Friction = 0.5f;
        myBody.OnCollision += myBody_OnCollision;

        b2 = BodyFactory.CreateBody(world, new Vector2(90, 500));
        b2.BodyType = BodyType.Static;
        b2.SleepingAllowed = false;
        b2.Mass = 0;
        sh2 = new CircleShape(1.0f, 1.0f);
        var fx2 = myBody.CreateFixture(sh2);
        fx2.Restitution = 0.7f;
        fx2.Friction = 0.5f;

        // 1 meter = 64 pixels
For every frame I call: world.Step(0.03333f);
And to get the ball position for drawing it from: myBody.Position
Marked as answer by anassisi on 2/11/2014 at 4:17 PM
Feb 11, 2014 at 11:18 PM