Carpetfizz
Carpetfizz

Reputation: 9149

Physijs collision events

I have two boxes. One spawns on the ground and the other is dropped on top of it. Gravity is turned on. I am trying to get the collision event listener to fire on the bottom box which is resting on the ground. However, nothing is logged.

var c = new Physijs.BoxMesh( new THREE.CubeGeometry( 5, 5, 5 ), new THREE.MeshBasicMaterial({ color: 0x888888 }) );
c.__dirtyPosition = true;
c.position.set(10, 0,-5);

c.addEventListener('collision', function(object){
    console.log("hello world"); // NOT FIRING
});

scene.add(c);

var p = c.clone();
p.__dirtyPosition = true;
p.position.y = 50;
scene.add(p);

I can't figure out what I'm doing wrong - could it be because of __dirtyPosition?

EDIT: I tested it without clone() and creating the second box anew, but it doesn't make a difference.

EDIT 2: It's worth mentioning that the simulation runs fine I just can't get the listener to work.

Upvotes: 0

Views: 854

Answers (1)

rgajrawala
rgajrawala

Reputation: 2188

Relevant GitHub Issue

It looks like the clone method is part of THREEjs, not Physijs. So your code just clones the physical material, not the physical mesh. You're just going to have to create another BoxMesh using the same code you did for c.

Upvotes: 1

Related Questions