Wrong collision in box2d

I am developing a game in which the user has to hit a high-speed ball. To get into the ball, I joined a rectangular body with an actor using a revolving hinge, and turned on his engine to rotate it at a given speed (engine speed). Now everything is perfect, but when the ball’s speed is high, it bypasses the rectal body. Using the collision, I found that the collision occurs, but the ball does not reflect after the collision. Since this only happens when the ball is at high speed, it bcoz the density of the bodies that collide. Or is it the engine of the revolving joint that is responsible for this? Am I missing something here?

Here is the code for both bodies

// method for a rectangular body

public Body createRectangleBodyPart(float x, float y, float width, float height, short groupIndex) { PolygonShape shape = new PolygonShape(); shape.setAsBox(width*WORLD_TO_BOX, height*WORLD_TO_BOX); MassData massData = new MassData(); massData.mass = 15; BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.KinematicBody; bodyDef.position.y = y*WORLD_TO_BOX; bodyDef.position.x = x*WORLD_TO_BOX; body = world.createBody(bodyDef); body.setMassData(massData); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 1; fixtureDef.friction = 100f; fixtureDef.restitution = 0.5f; fixtureDef.filter.groupIndex=groupIndex; body.createFixture(fixtureDef); shape.dispose(); return body; } 

// ball body method

  public Body createRoundBodyPart2(float x, float y, float radius, short groupIndex, float density, int mass) { CircleShape shape = new CircleShape(); shape.setPosition(new Vector2(0, 0)); shape.setRadius(radius*WORLD_TO_BOX ); // *18 BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody; bodyDef.position.y = y*WORLD_TO_BOX; bodyDef.position.x = x*WORLD_TO_BOX; MassData massData = new MassData(); massData.mass = 8; Body body = world.createBody(bodyDef); body.setMassData(massData); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 0.5f; fixtureDef.restitution=0.007f; fixtureDef.filter.groupIndex = groupIndex; body.createFixture(fixtureDef); shape.dispose(); return body; } 
+2
source share
2 answers

Try using the isBullet=true property on the ball body

+3
source

You tried to play with these properties: density, friction and restitution.

The ball can move so fast that when hit with a rectangular body, the ball strength must be high for the rib body. This means that the ball cannot be stopped by the rib body, so it passes through it.

Just to guess.

+1
source

Source: https://habr.com/ru/post/945715/


All Articles