Collisions two objects



Hello. I wrote a function that checks the collision of an object and an array. Also works and collision check of two objects, i can add pozition z but not need now. Its cool for me but maybe there is a ready function for this in three js?
And how check collision if i rotating any object?

function intersectObjMas(obj, mas) {
for (var i = 0; i < mas.length; i++) {
if (obj.position.x+obj.geometry.parameters.width/2 > mas[i].position.x-mas[i].geometry.parameters.width/2 
&& obj.position.x-obj.geometry.parameters.width/2 < mas[i].position.x+mas[i].geometry.parameters.width/2 
&& obj.position.y+obj.geometry.parameters.height/2 > mas[i].position.y- 
mas[i].geometry.parameters.height/2 && obj.position.y-obj.geometry.parameters.height/2 < 
mas[i].position.y+mas[i].geometry.parameters.height/2) {
isIntersect = 1;

if (isIntersect) refresh();



Look there @looeee collision-detection

Did you see that?

This is my simple test example:
( It’s in German, but with easy to translate. This is how I do it . )


Since you are using the position and the geometry of the object, you can use the built in ThreeJS function intersectsBox(). You can clone the original geometrys’ bounding boxes, apply their object’s transform matrix to them and check for intersections between them.

An example of this is discussed here:

With the relevant code below

function detectCollisionCubes(object1, object2){
  object1.geometry.computeBoundingBox(); //not needed if its already calculated
  var box1 = object1.geometry.boundingBox.clone();

  var box2 = object2.geometry.boundingBox.clone();

  return box1.intersectsBox(box2);


its amazing. Thanx!!!