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

Simple collision - First time using farseer

Topics: User Forum
Apr 29, 2010 at 11:21 AM

Hi everyone,

I have just started using Farseer and I'm trying to follow the included samples to create a simple collision system between some rectangles and apply gravity to them. After following the samples, and to start things off, I created just one box and all I'm trying to do is to apply gravity. I did the following:

class Buildings : Minigame
        PhysicsSimulator physicsSimulator = null;
        Texture2D background;
        Texture2D brickTexture;
        ArrayList bodies = new ArrayList();
        Body test;

        int windowWidth;
        int windowHeight;

        float brickMass = 1.0f;

        public Buildings(int windowWidth, int windowHeight)
            this.windowWidth = windowWidth;
            this.windowHeight = windowHeight;

            this.background = Renderer.getContent().Load<Texture2D>("buildings/sky");
            this.brickTexture = Renderer.getContent().Load<Texture2D>("buildings/buildings_brick");

            this.physicsSimulator = new PhysicsSimulator(new Vector2(0.0f, 200.0f));
            this.test = BodyFactory.Instance.CreateRectangleBody(this.brickTexture.Width, this.brickTexture.Height, brickMass);
            this.test.Position = new Vector2(100, 100);

            GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, this.test, this.brickTexture.Width, this.brickTexture.Height);

        private void update(GameTime gameTime)
            KeyboardState kbState = Keyboard.GetState();
            MouseState mState = Mouse.GetState();

            //Update the physics simulator
            this.physicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);


        private void draw(GameTime gameTime)

            Renderer.getSpriteBatch().Draw(background, new Rectangle(0, 0, windowWidth, windowHeight), Color.White);

             Vector2 origin = new Vector2(this.brickTexture.Width / 2.0f, this.brickTexture.Height / 2.0f);
            Renderer.getSpriteBatch().Draw(this.brickTexture, test.Position, null, Color.White, test.Rotation, origin, 1, SpriteEffects.None, 0);

            Console.WriteLine(" >>> Test: " + test.Position.X + ", " + test.Position.Y + " => " + test.Rotation);

        public override void play(GameTime gameTime)


However, nothing happens, the box is just lying there in the same place... I'm probably missing something very stupid, but can't figure out what... Any help is appreciated. : P

Thanks in advance...

Apr 29, 2010 at 2:04 PM
You need to add the Body object to the physics simulator.
Apr 29, 2010 at 2:10 PM

Thanks for your answer : D Hmm, isn't that automatically done by calling

 GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, this.test, this.brickTexture.Width, this.brickTexture.Height);