<small id='7YsPr'></small><noframes id='7YsPr'>

    <i id='7YsPr'><tr id='7YsPr'><dt id='7YsPr'><q id='7YsPr'><span id='7YsPr'><b id='7YsPr'><form id='7YsPr'><ins id='7YsPr'></ins><ul id='7YsPr'></ul><sub id='7YsPr'></sub></form><legend id='7YsPr'></legend><bdo id='7YsPr'><pre id='7YsPr'><center id='7YsPr'></center></pre></bdo></b><th id='7YsPr'></th></span></q></dt></tr></i><div id='7YsPr'><tfoot id='7YsPr'></tfoot><dl id='7YsPr'><fieldset id='7YsPr'></fieldset></dl></div>
    <legend id='7YsPr'><style id='7YsPr'><dir id='7YsPr'><q id='7YsPr'></q></dir></style></legend>
    • <bdo id='7YsPr'></bdo><ul id='7YsPr'></ul>
  1. <tfoot id='7YsPr'></tfoot>
    1. 在 libgdx 中,如何向 box2d Body 对象添加摩擦力?

      时间:2023-07-28

      <i id='kxGv5'><tr id='kxGv5'><dt id='kxGv5'><q id='kxGv5'><span id='kxGv5'><b id='kxGv5'><form id='kxGv5'><ins id='kxGv5'></ins><ul id='kxGv5'></ul><sub id='kxGv5'></sub></form><legend id='kxGv5'></legend><bdo id='kxGv5'><pre id='kxGv5'><center id='kxGv5'></center></pre></bdo></b><th id='kxGv5'></th></span></q></dt></tr></i><div id='kxGv5'><tfoot id='kxGv5'></tfoot><dl id='kxGv5'><fieldset id='kxGv5'></fieldset></dl></div>
        <tbody id='kxGv5'></tbody>

        • <small id='kxGv5'></small><noframes id='kxGv5'>

        • <legend id='kxGv5'><style id='kxGv5'><dir id='kxGv5'><q id='kxGv5'></q></dir></style></legend>

          <tfoot id='kxGv5'></tfoot>
            <bdo id='kxGv5'></bdo><ul id='kxGv5'></ul>
              • 本文介绍了在 libgdx 中,如何向 box2d Body 对象添加摩擦力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我对 libgdx 非常满意,喜欢使用它.但是,我是 box2d 的新手,所以我希望比我更聪明的人能帮助我.

                I'm having an absolute blast with libgdx, love using it. However, I am a newbie with box2d, so I was hoping someone smarter than me could help me out.

                我有一个简单的测试屏幕,其中一堆静态方形瓷砖组成了一个地板,一个动态的身体(一个圆圈)在周围反弹.

                I have a simple test screen, where a bunch of static square tiles make up a floor, and a dynamic body (a circle) bounces around.

                我想做的是增加地板的摩擦力,这样球就不会滚动得那么厉害.就像地板是草而不是木头.

                What I'm trying to do is to increase the friction of the floor so the ball doesn't roll as much. Like the floor was grass instead of wood.

                我在网上找到了一些东西,但似乎都不起作用.我尝试过的最有希望的事情是:

                I found a couple of things online, but neither seem to work. The most promising thing I tried is this:

                tileBody.getFixtureList().get(0).setFriction(0.9f);
                

                但它似乎什么也没做.

                阅读 box2d 文档建议我在最初定义对象时应该在夹具 def 上设置摩擦:

                Reading the box2d docs suggests that I should set friction on the fixture def when I define the object originally:

                FixtureDef fdef = new FixtureDef();
                fdef.shape = wallshape;
                fdef.density = 1.0f;
                fdef.friction = 0.9f;
                

                但是,这似乎也无法阻止球滚动.

                However, this doesn't seem to stop the ball rolling much either.

                有没有更好的方法来做到这一点?我可以减少恢复原状,但这只会阻止它反弹,对吗?

                Is there a better way of doing this? I can reduce the restitution, but that'll just stop it bouncing as much right?

                推荐答案

                    Body groundBody = world.createBody(groundBodyDef);  
                    PolygonShape groundshape = new PolygonShape();  
                    groundshape.setAsBox(30, 1.0f);   
                    FixtureDef groundFixture = new FixtureDef();
                    groundFixture.density=0.0f;
                    groundFixture.shape = groundshape;
                    groundFixture.restitution = .5f;
                    groundFixture.friction=0f;
                    groundBody.createFixture(groundFixture);
                    groundshape.dispose();
                

                这对我有用.如果沿着地面移动的物体有摩擦并且不是由暗物质构成,它们应该会减速.

                This worked for me. Provided the things moving along the ground have friction and aren't made of dark matter, they should slow down.

                这篇关于在 libgdx 中,如何向 box2d Body 对象添加摩擦力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Libgdx、物理、加速和 FPS 下一篇:LibGDX 闪烁

                相关文章

                最新文章

                    <bdo id='vhCI4'></bdo><ul id='vhCI4'></ul>

                1. <legend id='vhCI4'><style id='vhCI4'><dir id='vhCI4'><q id='vhCI4'></q></dir></style></legend>

                  <small id='vhCI4'></small><noframes id='vhCI4'>

                  1. <tfoot id='vhCI4'></tfoot>
                  2. <i id='vhCI4'><tr id='vhCI4'><dt id='vhCI4'><q id='vhCI4'><span id='vhCI4'><b id='vhCI4'><form id='vhCI4'><ins id='vhCI4'></ins><ul id='vhCI4'></ul><sub id='vhCI4'></sub></form><legend id='vhCI4'></legend><bdo id='vhCI4'><pre id='vhCI4'><center id='vhCI4'></center></pre></bdo></b><th id='vhCI4'></th></span></q></dt></tr></i><div id='vhCI4'><tfoot id='vhCI4'></tfoot><dl id='vhCI4'><fieldset id='vhCI4'></fieldset></dl></div>