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

Modeling wheels in Farseer

Topics: Developer Forum, User Forum
Jan 10, 2009 at 11:04 PM

I am writing a small demo to evaluate Farseer as a physics engine for my new project.

The demo is simply spawning a few rectangles and a sphere that is controlled by the player (the directional keys apply a torque). I create the CircleGeom with radius 1.0 and 64 section but still the movement is far from being smooth and the circle constantly jumps. Am I doing something wrong?

Jan 10, 2009 at 11:12 PM
No, you are doing nothing wrong. Farseer Physics sees all shapes as polygons, that means that circles are actually not circles, but an approximation of a circle. This causes the ball to behave differently from what you might expect from a circle. If you apply more edges to the circle, you will get better results. I've seen some people get good results with up to 360 edges, try experimenting a little.

We do have plans of supporting the circle shape (real circles) in future versions. Further information on this will soon be released here as we start up the planning stage for Farseer Physics 2.1.

Oh, and as a sidenote. You might want to create a real user here on Codeplex. It enables us to contact you directly and having your own identity have its benefits compared to public accounts.
Jan 10, 2009 at 11:17 PM
Thanks for the prompt reply.

The problem is that I have already tried with very high numbers of vertices and I get a weird bug where spheres would eventually pass through the floor =( That doesn't happen with 128 vertices. The allowed penetration is set to something very low.

Yes I will eventually make an account :)

Jan 10, 2009 at 11:31 PM
Can you paste the code that you use to create the circle? a radius of 1 seems very low.

Also, depending on how your game works, you can play with the restitution of the ball to minimize the bouncing (you can read about the restitution coefficient in our manual).
Jan 10, 2009 at 11:51 PM
        public GameCircle(Shape.Circle circle, float radius, float mass, bool isStatic, FarseerGames.FarseerPhysics.PhysicsSimulator physicsSimulator, Vector2 initialPosition)
   = circle;
            body = FarseerGames.FarseerPhysics.Factories.BodyFactory.Instance.CreateCircleBody(radius, mass);
            body.Position = initialPosition;
            body.IsStatic = isStatic;
            FarseerGames.FarseerPhysics.Collisions.Geom collisionGeometry = FarseerGames.FarseerPhysics.Factories.GeomFactory.Instance.CreateCircleGeom(body, radius, 128);
            collisionGeometry.FrictionCoefficient = 0.1f;

I tried to set the restitution to 0 but it didn't seem to change things.
Jan 10, 2009 at 11:56 PM
I set radius to 1.2f and mass to 1.0f for that instance.
Jan 10, 2009 at 11:59 PM
Still, a radius of 1.2 is very low. Do you have a scaling system in place that scales up the values?
I've just changed Demo2 from the XNA Simple Samples to have a circle of radius 10 and 128 sides (and have a border and gravity), it seems to work fine.
Jan 11, 2009 at 12:17 AM
I wanted to use an unit as a meter and it's very common to have objects with 1 meter radius. I never had numerical problems in using units in meters in past.
Jan 11, 2009 at 12:21 AM
Indeed it is, but as Farseer Physics uses pixels as standard, I was wondering where you got those numbers from. Thanks for clearing that up.
Jan 11, 2009 at 12:26 AM
I thought I read somewhere that it is not a good idea to have 1 unit = 1 pixel as you would get numbers over 1000 (resolution is 720p and you might have objects outside the screen).
Jan 11, 2009 at 12:34 AM
Using meters versus pixels has its advantages and disadvantages. We do have a convert class to help convert between pixels and meters, but for most games it's not really necessary. Erin Catto from Box2D (Which Farseer Physics is based on) has argued that using smaller values minimize numerical errors and fits better into the engine because it's optimized to the MKS (Meter, Kilogram, Second) system.

Farseer though is based on an old Box2D (Back when Box2D lite existed) and does not necessarily have to use meters. Our convertion helper class is also just a fancy wrapper for converting between pixels and meters with respect to a ratio. It still give the engine pixels as it's unit.
Jan 11, 2009 at 11:25 AM
There aren't any settings I could change to use smaller scales? For instance by reducing the Grid size or something else?

Thanks for your replies :)