platformer with Farseer

Topics: Developer Forum
Aug 31, 2009 at 8:24 AM

Hello. I want to make a platformer using Farseer and I've run into a problem. I want to have some platforms that you can jump through, but not fall through them. Any ideas how I could do that?

Aug 31, 2009 at 12:18 PM

Well, I don't have any immediate solutions, but here are some possible ideas to explore:

- Hook onto the OnCollision event of the platforms and check the velocity vector of bodies colliding with it. If the velocity vector has a negative Y component, reject that collision (e.g. by returning false from the event handler), since it's a colliding body going up. If the Y component is positive, then it's going down, so accept the collision by returning true from the handler.

- On the same collision event, check for the Normal of the contact point. If the normal points downward from the platform, then it's colliding from an object coming up, and in that case reject the collision. (This will probably have strange side-effects as soon as the object pops up the upper side of the platform)

Personally I would try the first idea, since it's seems easier and less prone to unwanted side-effects. However, I could be missing something or there may be other better ideas lying around.

Best regards,

Gonçalo

 

Aug 31, 2009 at 12:35 PM

thank you for your answer! I tried the first solution and it works like a charm :) I'll try the second one too and see which works better.