首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PhysicsJS -两个物体之间的碰撞永远不会结束

PhysicsJS -两个物体之间的碰撞永远不会结束
EN

Stack Overflow用户
提问于 2014-11-16 18:38:02
回答 1查看 711关注 0票数 1

我有个简单的js:

代码语言:javascript
复制
Physics(function( world ){

        //Defining object
        var renderer = Physics.renderer('canvas', {
            el: 'viewport', // id of the canvas element
            width: 500,
            height: 200
        });
        
        var ball = Physics.body('circle', {
            x: 250,
            y: 0,
            radius:10,
            restitution: .8,
            mass: 3,
            vx: 0
        });
        
        var box = Physics.body('rectangle', 
            {
                x: 250,
                y: 150,
                width: 50,
                height: 20,
                restitution:.5,
                treatment: "static"
            }
        );
                
        // Add them to the world
        world.add( renderer );
        world.add( ball );
        world.add( box );        
        
        //Add physical behaviours
        world.add( Physics.behavior('constant-acceleration') );//add gravity
        world.add( Physics.behavior('body-impulse-response') );//make obdies bounce (react to impulse)
        world.add( Physics.behavior('body-collision-detection') );//detect collision between bodies
        world.add( Physics.behavior('sweep-prune') );
        world.add( Physics.behavior('edge-collision-detection', //dectect collision with edges
                {
                    aabb: Physics.aabb(0, 0, 500, 500),
                    restitution:.3
                }
            )  
        );
        
        //START playing
        world.on('render', function( data ){
            var renderer = data.renderer;
        });

        // subscribe to ticker to advance the simulation
        Physics.util.ticker.on(function( time, dt ){
            world.step( time );
        });

        world.on('step', function(){
            world.render();
            console.log(ball.state.vel._[1]);
        });

        // start the ticker
        Physics.util.ticker.start();        

    });
代码语言:javascript
复制
canvas {border:1px solid;}
代码语言:javascript
复制
<script src="http://wellcaffeinated.net/PhysicsJS/assets/scripts/vendor/physicsjs-0.6.0/physicsjs-full-0.6.0.min.js"></script>
<canvas id="viewport" width="500" height="200"></canvas>

创造了一个静态平台和一个球落在上面的世界。球又落又跳,然后弹跳又慢又慢,但它永远不会结束。我在bodies属性中设置了restitution < 1

我哪里错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-17 19:57:05

这是当前版本的physicsJS的一个bug。你的密码是正确的。试着从github的0.7支部取走。您将需要检查回购和运行“咕噜区”。

https://github.com/wellcaffeinated/PhysicsJS/tree/0.7.0

注意,这不是一个0.7版本。此代码仍在开发中。我建议监视物理and,并在它准备好时获得实际的0.7版本。应该很快就会。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26960598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档