I just started doing Box2d programming. I'm trying to create a platform game. When the player (dynamic body) jump and landed on the moving platform (kinematic body), I need to make the player stay and move together with the platform. So i try using distance joint to "stick" the player to the platform. However, I've set the anchor point-Y so that the player will stay above the platform but I don't want to set a fix X. What approach should i use?
eg:
- A.When player jump from right to left, it will land on left.
- B. When player jump from left to right, it will land on right.
So when the player jump from any position, the X will be based on the player except Y is fix. Thank you.
b2DistanceJointDef jointDef;
b2Vec2 playerAnchor = curPlayerBody->GetWorldPoint(b2Vec2( 1, -0.8));
jointDef.Initialize( curPlayerBody, curPlatformBody, playerAnchor, curPlatformBody->GetWorldCenter() );
jointDef.length = 0;
jointDef.dampingRatio = 0;
jointDef.frequencyHz = 0;
jointDef.collideConnected = false;
playerPlatformJoint = (b2DistanceJoint*)world->CreateJoint(&jointDef);