【问题标题】:ThreeJS & PhysiJS not triggering collision eventThreeJS 和 PhysiJS 未触发碰撞事件
【发布时间】:2017-02-01 10:52:30
【问题描述】:

我在使用 PhysiJS 和 Three JS 时遇到问题,我无法处理碰撞事件。

Github 上的存储库: https://github.com/kevrmnd/soccer-physics(在 script.js 文件中)

我有一个地面和一个球,我在球上放置了一个事件监听器,当它落在地面上但没有输出时应该提醒或记录一些东西。

这是我设置场景和重力的方法:

scene = new Physijs.Scene({ fixedTimeStep: 1 / 120 });
scene.setGravity( new THREE.Vector3( 0, -30, 0 ) );

这是我的地盘:

    loader = new THREE.TextureLoader();

    // Materials
    ground_material = Physijs.createMaterial(
        new THREE.MeshStandardMaterial({ map: loader.load( 'img/grass.png' ) }),
        1,
        0.6
    );
    ground_material.map.wrapS = ground_material.map.wrapT = THREE.RepeatWrapping;
    ground_material.map.repeat.set( 4, 4 );

    // Ground
    ground = new Physijs.BoxMesh(
        new THREE.BoxGeometry( 30 , 1, 60 ),
        ground_material,
        0
    );
    ground.receiveShadow = true;
    scene.add( ground );

最后是我的球:

    shape_material = Physijs.createMaterial(
        new THREE.MeshNormalMaterial(),
        0.5, // low friction
        0.8 // high restitution
    );

    shape = new Physijs.SphereMesh(
        new THREE.SphereGeometry( 0.5, 25, 25 ),
        shape_material,
        0.75
    );

    shape.addEventListener( 'collision', function(){
        alert( 'hey' );
    } );

    shape.position.z = 20;
    scene.add( shape );

我真的不明白为什么这不会触发事件。我需要你的帮助:-)

【问题讨论】:

    标签: three.js collision physijs


    【解决方案1】:

    好的,我在这里找到了解决方案:https://github.com/chandlerprall/Physijs/issues/248

    只需要修改 physijs_worker.js 文件中的两行!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 2019-07-25
      • 2015-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      相关资源
      最近更新 更多