在box2d中没有正确的碰撞 [英] not proper collision in box2d

查看:148
本文介绍了在box2d中没有正确的碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款用户必须击中高速球的游戏。为了击球,我加入了一个长方体,演员使用旋转关节并启用其电机,以指定的速度(电机速度)旋转它。现在一切都很完美,但有时当球的速度很高时,它绕过了直肠体。使用碰撞列表器我发现碰撞正在发生,但碰撞后球没有反射。
因为只有当球高速行驶时才发生这种情况,是碰撞的物体密度是否为bcoz。或者它的旋转关节电机是谁?我在这里遗漏了什么吗?

I am developing a game in which the user have to hit a high speed ball. To hit the ball I have joined a rectangular body with the actor using revolute joint and enabled its motor, to rotate it with a specified speed(motor speed). Now everything is perfect but sometime when ball`s velocity is high , it is bypassing the rectagular body. Using collision listner i found that collision is happening but ball is not getting reflected after collision. As this is happening only when ball is on a high speed, is it bcoz of density of bodies that are colliding . Or its the motor of revolute joint that is responsible for it ?? Am i missing something here??

以下是两个机构的代码

//矩形体的方法

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;
}

//球体方法

    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;
}


推荐答案

尝试使用 isBullet = true 球身上的属性

这篇关于在box2d中没有正确的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆