0

I have an issue while using PhysiJS and Three JS, I can't handle collision event.

Repository on Github : https://github.com/kevrmnd/soccer-physics (in script.js file)

I have a ground and a ball, I put an eventlistener on the ball which should alert or log something when it falls on the ground but there is no output.

Here is how I set scene and gravity :

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

Here is my ground :

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

And finally my ball :

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

I really don't understand why this doesn't trigger an event. I need your help :-)

bookah
  • 1

1 Answers1

0

Ok I found the solution here : https://github.com/chandlerprall/Physijs/issues/248

Just had to modify two lines in physijs_worker.js file !

bookah
  • 1