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

Two Geoms attached to one Body - bug

Topics: Developer Forum, User Forum
Jul 9, 2009 at 7:45 PM


There is an extremely frustrating bug in my program which I don't know if it's caused by my code or farseer. The situation is this:

I have a set of vertices representing two rectangles which overlap in the middle. I create a single body & two seperate geom (each respective to one rectangle) and attach both geoms to the body.


The bug is in the collision: the outer portion of the geometries always only intresect with the central (overlapping) section. It might be a little hard to explain, so if you want just ask for pics and i'll post up some screenshots.

Now, if the two rectangles dont overlap each other in the middle the collisions still dont work fine, and I think it collides with the space in between the two rectangles somehow - its hard to explain even for me who's seen it.

Another oddity is if the central overlapping section isnt a square but rectangular, then you can see that when the bodies rotate, its like the underlying geometry and/or vertices don't (although the rendered image rotates fine) - which makes the collision seem even more random.


This bug is really aggravating me for a few days now, I really need this to work because I want to use the collision categories system within a single body..

Hopefully, someone tried doing this before me and can tell me if I'm doing something wrong



Jul 9, 2009 at 10:57 PM

Using two geometries with one body should work fine. The samples that use the "Agent" (a cross with 4 yellow circles) uses the same body for all its geometries.

I would like to see that screenshot or even better; a demo. If you are able to send me your demo I will take a look at it.

Jul 10, 2009 at 10:46 AM

Well, I've actually decided to remake my system to simply use a single geom per body and then use more bodies, so I can't give you a demo of the bug without undoing all my changes... but just for the sake of reporting a bug I looked at the code for creating the agent and firstly, the geometries aren't custom made from a list of vertices, but using the CreateRectangleGeom or EllipseGeom functions.

Secondly in my code I created the body itself from the vertices, not from a bounding rectangle as is with the agent body.

I'm thinking it might have been a problem with the winding order of the vertices, now that I think about it that would make sense, as the collisions seemed somehow to be inverted. Although I have no idea how to fix that.

Here is a diagram I drew up of bug:




Jul 10, 2009 at 5:33 PM

The CreateRectangleGeom and its friends are all helpers to help you create geometries. All geometries needs to have a MOI (Moment Of Inertia) and the correct amount of vertices. Because the default narrow phase collider is the distance grid, you not only need vertices in each corner of a rectangle, you also need along the sides. All of this is automatically done with the factories so I would suggest you use those.

The order of your vertices should not make any difference. We automatically check if you put them in clock-wise order and reverse them. You need to remember that (0,0) is the center of the geometry so all your vertices should be relative to (0,0). (Just to underline this point: (0,0) is NOT the topleft corner, it is the center)

I'm not sure I understand your diagram (Paint rocks!) but I hope the info I just wrote will help you on your way. The agent from the samples works like it should and you should create yours like the agent is created.

Jul 10, 2009 at 9:27 PM

Since you created the body from a set of vertices (a single body), why not create the geom using the same set of vertices?