Answer the question
In order to leave comments, you need to log in
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);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question