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

need help with bug with certain colliding geometries

Topics: Developer Forum, User Forum
Aug 4, 2009 at 3:19 PM


I am already 3 days trying to solve a bug with the collision detection.

The bug happens when I have a geometry which is asymmetrical (a vertex in one quadrant aroung the origin does not have a corresponding vertex in the opposite quadrant), and/or if I have a shape which intersects in the middle (like an '8' shape).

The problem is that it seems in either of these cases the body seems to become dissattached with the rendered image, in the second case siginificantly more so.

The way I keep track of the rendered image is a way very similiar to the way shown in Simple Silverlight Samples project, by simply attaching a body to the graphic updating the position according to the body, and translating the origin of the graphic to the center (by getting the bounds of the Silverlight geometry). The only real difference between the given sample code and mine is that I use a "path" geometry instead of directly using the rendered geometry so i can use PolyLines.


I've been busting my head on this bug for over 3 days, and I know there are plenty of more experienced coders on this forum than myself; I'd really appreciate any help, any ideas would be really helpful!  If you want more details, please just say so.

Thanks in advanced


Aug 4, 2009 at 6:14 PM

i'm prolly not exactly "more experienced" than you, but did you make sure the offset is correct for the geometry? i had a similar problem with the terrain in my project.

Aug 4, 2009 at 8:37 PM
Edited Aug 5, 2009 at 2:45 PM

Could you post an image of this?

Aug 5, 2009 at 10:52 AM
Edited Aug 5, 2009 at 1:01 PM


The thing is, the offset seems to be correct, but only for symettrical geometries and ones which are not in the shape of an "8."

My hope is that maybe someone saw the same bugs happening to them for asymmetrical and/or "8" shaped geometries, or if anyone has any ideas where this bug is happening



Sorry, what do you mean "hook up an imagine?"



Well, I solved the bug with the asymmetrical geometries.

The problem was that I set the center of rotation of my sprite to the center of the bounding box, instead of using the vertices.GetCentroid() and using the centroid.

However, the "8" figure geometry is still behaving very strangely, so I'm not completely satisified. Any ideas why any other shape would work, just not an "8"?

Aug 5, 2009 at 2:49 PM

That was a pretty bad typing error. I simply would like to see an illustration of what you mean. An eight shape should work great, but you would only be able to use the outline of the 8-shape and not the actual holes in it. Not unless you split the shape up into at least 3 geometries. (bottom, middle, top). How is your vertices defined for the 8-shape?

Aug 5, 2009 at 3:49 PM
Edited Aug 5, 2009 at 3:59 PM

This is the problematic shape:

Image Hosted by

The problem with it is that somehow it always seems offcenter. Also, the collisions sometimes glitch. To be sure, there are vertices all across those lines, so its not a problem of not enough vertices... so what is it?



Aug 5, 2009 at 5:19 PM

Thanks for the illustration, it makes things a little more clear.

First of all, the offcenter is probably caused by not drawing the texture there the geometry is. Have you tried to implement the PhysicsSimulatorView.cs file from the samples? they are a great help in determining if it is the drawing code or something is wrong with the physics engine (Almost never the case). I will try to provide some code (in the physics engine) that should ease the extraction of the centroid from a geometry.

The center of your geometry (where they the two triangles meet) might cause some trouble because it is very thin. Using one vertices list for the whole geometry might give some weirdness in that exact point. If that is the case, you should try to create two triangles and fix them to one body instead.

If you experience problems at the points of the triangles, it is because they are to thin too. You need to lower the default collision grid cell size to something that give stable collisions.

Aug 6, 2009 at 8:45 AM

Okay, thanks for the help genbox, I'll to lower the collision grid cell and I think that might help. Maybe I'll even try to write manual code to smooth out the corners, although I'm not really sure how to do that.

Does the PhysicsSimulatorView work in Silverlight as well? I thought it was only supported by XNA currently.


Aug 6, 2009 at 11:07 AM

We have a fully implemented XNA version and only a partial WPF/Silverlight version. You could create your own tho - a lot of the stuff the debug view does is not really used. It is mostly just the visualization of the vertices and contacts that are important.