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

What changed in polygon placement?

Jul 19, 2008 at 8:19 AM
Edited Jul 19, 2008 at 9:33 AM
It's been a while creating games with farseer. I took all my old projects and updated them to Farseer
It works fine.... except objects created from polygons.

If I create a circle it works fine, but if I create a polygon body, there seems to be an offset in the polygons.
What is changed between that I used before and that could cause this?

Edit: Seems to be in too

Edit2: Seems to be caused by CreatePolygonGeom() and GetMomentOfInertia() trying to center the vertices on the centroid. Commenting out this fixes my problem.

Would like to hear if others have the same problem or I'm just adding the wrong points (for the polygons) to the engine.
Jul 25, 2008 at 9:51 PM
I'm actually seeing the same problem.  I've created a polygon static object and updated it's position but all of the vertices seem to be about negative 80-100 units on the X-axis.  I am drawing the polys on screen and everything lines up except for the collisions which think the objects are farther to the left than they really are......
Jul 25, 2008 at 10:04 PM
Actually, I found my problem.

I was creating the polygon body and then doing a myBody.Position = new Vector2(0,0);

After that I would then set the body position to be where I expected the top-left corner to start on the game field.  What I didn't realize is that the polygon body position is at the centroid of the poly, not the upper-left corner.  This was causing my poly to appear "to the left" in collision but not visible as my visible vertices were put down prior to the centroid calculation (based on the verts passed to the polygon create command.)  Anyway, now that I know the body position is at the centroid I just adjust the body position in relative terms and it works out fine.