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

Creating non-solid objects?

Topics: User Forum
May 12, 2010 at 6:53 AM

Hello everyone.

I am fairly new at working with Farseer, and integrated v2.1.3 into my game. I want to be able to create objects that react to a collision but are not solid. A good example of what I'm thinking is a pile of leaves. I want to eventually create a pile of leaves that when you jump into them fly off in all directions, but the player doesn't get stuck standing on it.

What's the best way to accomplish this?

May 12, 2010 at 10:01 AM
Edited May 12, 2010 at 10:05 AM

Use the geom's IsSensor property:

geom.IsSensor = true;

To make it respond:

geomSensor.OnCollision += new FarseerGames.FarseerPhysics.Collisions.CollisionEventHandler(OnCollision);

        private bool OnCollision(Geom geometry1, Geom geometry2, ContactList contactlist)
              // Place the code to create your leaves here

Don't forget to use collisioncategories or something to make sure only the player can trigger it.

May 12, 2010 at 1:07 PM

I dont think you can have the leaves react to the collision without affecting the player. But using tinytiny's method you can manually apply force to the whole pile of leaves when the player touches it.

Also remember that you can return false from an OnCollision event to cancel the collision. This stops the collision for both objects though. I use this for point bubbles which I want the player to pop without slowing him down after the collision.

May 13, 2010 at 5:37 AM

Worked well enough, thanks a million!