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

Collisions Problems - halfway penetration, bounciness

Topics: User Forum
Jan 14, 2007 at 7:19 PM
I've been using just the FarseerGames.FarseerXNAPhysics namespace in my game - it's a 2d game being output via the graphics card, so I rely on Farseer just to generate the collision responses, and update my 3d objects accordingly.

My first attempt, with two rectangles ( and RectangleRigidBody objects ) worked okay - however, when I switched to using PolygonRigidBody objects, my objects began intersecting each other halfway. After looking at the RectangleRigidBody code, and how it split up the object into a larger series of points for greater precision, I wrote an algorithm that chunked up my general polygon coordinates into a smaller series of points ( using Bresenham's line drawing algorithm ). Strangely enough though, the objects still display the same behavior, even when I pass in an absurd number of points as the Vertices array.

My question is, what can I do to avoid this? Are there general problems using the PolygonRigidBody? Is there some magic method to splitting up your point distances that isn't documented?


Jan 15, 2007 at 12:53 PM
Are your objects moving fast? This is most often the cause of interpenetration.

Also, when you create your vertices. Are you creating them as if they are centered around the orgin? ie for a box it would be
(-1,-1), (-1,1), (1,1), (1,-1) Try that as a test and see how it works.

On a side note. Do you mind sharing your code to chunk up a polygong? That is on my list to add and I wouldn't mind seeing how you did it.

Jan 17, 2007 at 1:05 AM
Sure thing - here's the pseudo code for the algorithm, from Wikipedia (generalized version) -'slinealgorithm

newvectors is what we'll be adding the result of the chunking op to
generalpolygoncoordinates is the list of all the interesting vectors in our polygon

newvectors = new list of 2d vectors
for each vector current in generalpolygoncoordinates
x0 := current.X
y0 := current.Y
next = get next vector in generalpolygoncoordinates, or first vector if current is last
x1 := next.X
y1 := next.Y
boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x0
int deltay := abs(y1 - y0)
real error := 0
real deltaerr := deltay / deltax
int y := y0
if y0 < y1 then ystep := 1 else ystep := -1
for x from x0 to x1
if steep then addnewpolygontolist(y,x) else addnewpolygontolist(x,y)
end if
error := error + deltaerr
if error = 0.5 then
y := y + ystep
error := error - 1.0

I call this for every set of Vectors, and have an extra step ( above, at the token SKIP ) where I check the current iteration of the progression of x from x0 to x1 against how chunked I want the polygon. I'm sorry for not posting my own code, but it's probably easier to deal with this then extricating any of my codecrap from what I currently have. Regardless, it works. :-)

Jan 17, 2007 at 1:06 AM
Holy shit this forum sucks - sorry for the munging up of the pseudo code and link.
Jan 17, 2007 at 2:21 AM

And I agree this forums stinks. I especially hate you you can't see the original post when you are writing your response!