If you look at the Velcro Physics (formerly Farseer Physics) code, you'll find an example called OneSidedPlatformTest
. Inside this test is the code required to create Fixtures that act in the manner you're requesting.
Essentially, you override the PreSolve
function in the following way:
protected override void PreSolve(Contact contact, ref Manifold oldManifold)
{
base.PreSolve(contact, ref oldManifold);
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
if (fixtureA != _platform && fixtureA != _character)
{
return;
}
if (fixtureB != _platform && fixtureB != _character)
{
return;
}
Vector2 position = _character.Body.Position;
if (position.Y < _top + _radius - 3.0f * Settings.LinearSlop)
{
contact.Enabled = false;
}
}
This relies on testing the top of the platform against the position of the character. Assuming the position of the character is at its feet, no collision is returned when the feet are not near the platform.
This method may work for you, but once you've implemented this override, it should be trivial to change the detection method to other strategies. For example, you could test the direction the character is traveling and only apply collision if the character is above the platform and not moving up.