I am working on my first game using libgdx with box2d. I am using a debugging tool to validate objects. I created several similar cars. Each car has a main body, which is a large polygon of 6 points (about 1 meter in length, 0.7 meters in height) and has 2 wheels connected by revolving joints.
The main car has a cannon and a machine gun, also through revolving units.
The problem I am facing is that most of the car does not collide as intended. When 2 cars fall into each other, they overlap, for example:

Some notes:
- Wheels and guns (smaller figures) do a great job with a collision. When the wheels touch the bodies stop.
- If I detect a collision using code, the collision actually occurs
- I tried this with a smaller object (a bullet fired from a machine gun), and I set the "isBullet" property of a true object, as I saw in another post ( not a correct collision in box2d ), but had the same result (the bullet is surrounded in red):

Here is the code I use to create the bodies:
protected Body createBody(Material material, Shape shape, BodyType type, WorldWrapper world) { BodyDef bodyDef = new BodyDef(); bodyDef.type = type; bodyDef.position.set(initialPosition); Body body = world.createBody(bodyDef); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = this.material.getDensity(); fixtureDef.friction = this.material.getFriction(); fixtureDef.restitution = this.material.getRestitution(); fixtureDef.shape = shape; body.createFixture(fixtureDef); return body; }
The car moves forward using engines on the steep joints of the wheels, constructed as follows:
public void goForward() { for (RevoluteJoint joint : wheelJoints) { joint.enableMotor(true); joint.setMotorSpeed(-this.engineSpeed); joint.setMaxMotorTorque(this.engineTorque); } }
I use the following values:
Density = 2500; Restitution = 0; Friction = 0.1; BodyType = Dynamic;
I use a world step of 1/60 second with an Iteration = 6 and positionIterations = 2
Any idea what I'm missing here?
source share