Hey guys,
I am doing simple collision in a project using intersectsBox. All game obstacles have hitboxes which are cubes, and the player has one as well.
In my update loop I am doing the following:
detectCollision(object1, object2){
var box1 = new Box3(new THREE.Vector3(), new THREE.Vector3());
box1.setFromObject(object1);
var box2 = new Box3(new THREE.Vector3(), new THREE.Vector3());
box2.setFromObject(object2);
return box1.intersectsBox(box2);
}
I am also when each obstacle is created computing their bounding boxes and updating their matrix worlds. I put these outside of my detection to avoid doing those in my update loop.
So the issue is, it seems like everything returns true for hitting my player when it is placed for the first time. It seems like some kind of race condition. I have been able to sort of hack around this, but the root cause I am uncertain of and keeps springing up. It seems like when I place a new object it automatically thinks it is hitting the player, even though it is nowhere near the player. So like my computeBoundingBox or updateMatrixWorld is not finishing before its checking for collision?
Thanks guys!