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

Changing Geometry size once body is created

Aug 7, 2007 at 7:09 PM
I am in the process of testing my animation system and have come across a somewhat interesting problem. I have all of my game entities as rectangleRigidBodies (at least for now... I plan to adopt the awesome new Farseer once released :)). Each entity has an associated tangible form that describes the texture and animations associated with it. Naturally I start the rigidBody size to be the size of the base texture for the entity, but the problem occurs when the entity starts to animate. Since different frames of animation are different sizes, I want to be able to adjust the size of the rigidBody for that entity based on the size of the current frame. I have not actually tried this yet, but wanted to see if this was frowned upon and if so, how one would go about resolving this issue. Thanks for your time!
Aug 7, 2007 at 9:59 PM
The problem is the collision grid for a geometry is pre-computed when the object is created. It's not really meant to be dynamcially modified during run-time. I've never tried it, but I have a feeling re-computing the distance grid in real-time would slow things down. Possibly it would be fast enough for very simple shapes with a very sparse distance grid.

The first thought that jumped into my head was that you could use multiple different size rectangle rigid bodies created up front and just swap them in and out as needed.


Aug 8, 2007 at 12:39 AM
Ah, that makes sense. Actually, the more I think about it, it may be worthwhile to just create the body to be the size of the largest frame. That way regardless of which frame is being shown, it will always fit inside the rigid body. My only concern with this are possible performance ramifications. The biggest frame is not much larger than the smallest frame and since collisions are on a per-pixel basis, this may be the best approach. Do you think this is a viable solution? Thanks again for your response and generosity to the XNA community; your engine is fantastic and I am ecstatic about the forthcoming release!
Aug 8, 2007 at 12:27 PM
I'm not sure I understand what you mean by "since collisions are on a per-pixel basis" Farseer doesn't do per-pixel collision detection. It uses the distance grid which is much faster than per-pixel detection.

I don't think performance will be an issue.