Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want that my character can jump through some of the tiles, like Mario does in this video: http://www.youtube.com/watch?v=zIPYzbNrNhc

In this video, Mario jumps up through orange platforms, but does not fall down through them.

How can I do that with Farseer?

share|improve this question
    
Related but for a different engine (some of the answers may still apply) gamedev.stackexchange.com/questions/50693/… –  Tetrad May 13 '13 at 21:26
    
I removed your code and "What should I change in my code?", because I felt that made this question too localized. If you feel like that's the question you need answered, you can revert it. However, I would vote to close if you choose to do that. :) –  Byte56 May 13 '13 at 22:36

1 Answer 1

up vote 7 down vote accepted

If you look at the Farseer Physics Engine 3.3.1 Testbed XNA 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.

share|improve this answer
    
+1 with the small addendum that, if implementing the last line in Byte56's answer, ensure that the character is completely above the platform/past object to avoid any oddities like a short jump getting the character stuck midway. –  Attackfarm May 14 '13 at 5:25
    
I always get this error message: 'WindowsGame2.Game1.PreSolve(FarseerPhysics.Dynamics.Contacts.Contact, ref FarseerPhysics.Collision.Manifold)': no suitable method found to override What is wrong? –  Bryan May 14 '13 at 8:38
    
Sorry Bryan, this is not a copy/paste answer you need to look at the example in code, see what overriding entails. This is a common programming practice. If you still can't figure it out, head to chat and I or someone else will help you. –  Byte56 May 14 '13 at 13:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.