A
A
Andy Voz2016-08-22 15:19:56
Game development
Andy Voz, 2016-08-22 15:19:56

Misunderstandings in box2d, what's wrong?

I'm making a toy on Libgdx + box2d. Simple platformer. Today I encountered something incomprehensible: I make moving platforms using KinematicBody, and I move them using the setLinearVelocity method. I want that when the player stands on the platform, he moved with it. Tried to do the following thing. In the update() method, where all the logic is updated, each frame wrote the following thing:

Array<Contact> contacts = world.getContactList();
        for (Contact contact : contacts){

            Fixture fa =contact.getFixtureA();
            Fixture fb = contact.getFixtureB();

            if((fa.getUserData() instanceof Player && fb.getUserData() instanceof MovingPlatform) ||
                    (fa.getUserData() instanceof MovingPlatform && fb.getUserData() instanceof Player)) {
                 player.p_body.setLinearVelocity(player.p_body.getLinearVelocity().x+1,player.p_body.getLinearVelocity().y);
            }
        }

And I discovered the following - the collision of the player with the platform is determined EARLIER than it actually happens. What kind of bullshit is this? And how to make a normal moving platform?
PS The world is updated like this: world.step(delta, 6, 2);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question