I am attempting to calculate collisions between two objects with bounding boxes as given by Profile - calrk - three.js forum.
My function is as follows:
function detectCollisionCubes(object1, object2) {
object1.geometry.computeBoundingBox(); //not needed if its already calculated
object2.geometry.computeBoundingBox();
object1.updateMatrixWorld();
object2.updateMatrixWorld();
var box1 = object1.geometry.boundingBox.clone();
box1.applyMatrix4(object1.matrixWorld);
var box2 = object2.geometry.boundingBox.clone();
box2.applyMatrix4(object2.matrixWorld);
if (box1.intersectsBox(box2)){
console.log("flagged")
setupLevel(2)
}
}
However, when I attempt to call updateMatrixWorld(); on my player (object one), it returns
Uncaught TypeError: object1.updateMatrixWorld is not a function
I have logged the object one and object 2 classes to console, which return
1. Player {direction: Vector3, camera: PerspectiveCamera, geometry: BoxGeometry, material: MeshBasicMaterial, playerModel: Mesh, …}
1. camera: PerspectiveCamera {uuid: "FD7868AB-8CF6-43C6-877D-5CE94ED64808", name: "", type: "PerspectiveCamera", parent: null, children: Array(0), …}
2. controls: PointerLockControls {domElement: body, isLocked: false, minPolarAngle: 0, maxPolarAngle: 3.141592653589793, connect: ƒ, …}
3. direction: Vector3 {x: 0.2549525589972969, y: 0.7968116683391837, z: 0.547805036358061}
4. geometry: BoxGeometry {uuid: "293D1574-B78B-4CA0-97DA-3AF8FA4D41A5", name: "", type: "BoxGeometry", index: Uint16BufferAttribute, attributes: {…}, …}
5. material: MeshBasicMaterial {uuid: "D0EBDBB5-0923-4595-8997-6D8571C93FA8", name: "", type: "MeshBasicMaterial", fog: true, blending: 1, …}
6. playerModel: Mesh {uuid: "5125B185-7FF7-4692-869F-AC94C8BD22E2", name: "", type: "Mesh", parent: null, children: Array(0), …}
7. __proto__: Object
and
1. Goal {geometry: BoxGeometry, material: MeshBasicMaterial, mesh: Mesh, type: 1}
1. geometry: BoxGeometry {uuid: "52F08CA0-3400-45AC-A28E-ED1D128ACEB8", name: "", type: "BoxGeometry", index: Uint16BufferAttribute, attributes: {…}, …}
2. material: MeshBasicMaterial {uuid: "D5800CCE-7FCE-4A36-9E4C-07B7DB5F046C", name: "", type: "MeshBasicMaterial", fog: true, blending: 1, …}
3. mesh: Mesh {uuid: "26A13948-6526-4A16-A2B0-606F1C5A3377", name: "", type: "Mesh", parent: Scene, children: Array(0), …}
4. type: 1
5. __proto__: Object
As both fall under the Object3D class to the best of my knowledge, how should i prevent this?