Problems with landing on moving platform

Hi guys,

I am making a 2D sidescroller that happens to have moving platforms. Thanks to your help I was able to implement them, but now I am facing another issue regarding them.

When the platform is moving downwards (it keeps moving up and down) and the player lands on it, they never actually collide (I put a breakpoint inside beginContact). The player keeps on accelerating, but his position is not updated accordingly as he accompanies the platform without touching it. Finally, the collision only happens when the platform starts to move up.

Then, I tried to set the players body bullet flag to true, and everything started to work as expected. Could someone explain to me how did this happen?
Are the moving platforms static or kinematic? If they're static, make them kinematic.

If they're already kinematic, are you using the SetLinearVelocity() function to move them or are you setting the positions directly? If you're setting the positions directly, use SetLinearVelocity instead.
Thanks for the answer!

They are Kinematic and I use setLinearVelocity to move them already =)
Hm, this is strange. What version of the engine are you using? There's a chance this might be a bug with Box2D
Thanks for the answer =)

I am using the latest version available at the google code page. I found it really weird too, I will try to reproduce it on the testbed and send it back to you. Where can I post it?
Finally was able to build the testbed and implement the test I wanted to show. It is very simple, ask the testbed to draw the contact points and you will see there are none. Also, I noticed that if I turn off Continuous Collision, contact points will appear.

So, here is the test:

Code: Select all

package org.jbox2d.testbed.tests;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.testbed.framework.TestbedTest;

public class MovingPlatformTeste extends TestbedTest {

   @Override
   public void initTest(boolean argDeserialized) {
        setTitle("Moving Platform Test");
      
        getWorld().setGravity(new Vec2(0, -100));
      
        PolygonShape polygonShape = new PolygonShape();
        polygonShape.setAsBox(10, 1);
       
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyType.KINEMATIC;
        bodyDef.position.set(0, 20);
        bodyDef.allowSleep = false;
        Body body = getWorld().createBody(bodyDef);
        body.createFixture(polygonShape, 5.0f);
        body.setLinearVelocity(new Vec2 (0.0f, -10.0f));
       
        polygonShape = new PolygonShape ();
        polygonShape.setAsBox(1, 1);
       
        bodyDef = new BodyDef ();
        bodyDef.type = BodyType.DYNAMIC;
        bodyDef.position.set(0, 100);
        bodyDef.allowSleep = false;
        body = getWorld().createBody(bodyDef);
        body.createFixture(polygonShape, 5.0f);
   }

   @Override
   public String getTestName() {
      return "Moving Platform Test";
   }

}

Cool, I'll take a look this weekend or next week
Hey, I would like to ask you something, sorry for offtopic, have you managed to 'sticky' your player to the platform while its moving?
Yes. Basically what I do is:

In the begin contact listener, if the character is touching a platform, I keep a reference of that platform and add the platform speed to the player's speed.

In the end contact listener, I just make the platfomr reference null.
Has this issue been solved?

Original thread: https://box2d.org/forum/viewtopic.php?t=8440