Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Three JS detect multiple moving object collision

I currently have multiple objects, each moving forward randomly like this

model.lookAt(position_x, 0, position_z);

setInterval(function(){
   model.translateZ(0.015);
}, 10);

I need each object to avoid crashing into each other during forward movements. I found this solution suggesting bounding boxes for collision detection but it only seems to be for collisions between two objects:

How to detect collision between two objects in JavaScript with Three.js?

Is it possible to have multiple objects each having their own collision detections?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's how you could do it :

var objectA = ...your first object...
var objectB = ...your second object...
var objectC = ...your first object...
var objectD = ...your second object...

firstBB = new THREE.Box3().setFromObject(objectA);
secondBB = new THREE.Box3().setFromObject(objectB);
thirdBB = new THREE.Box3().setFromObject(objectC);
fourthBB = new THREE.Box3().setFromObject(objectD);

const BBs = [firstBB, secondBB, thirdBB, fourthBB];


// at each frame, you could do this to check if some objects are colliding :
BBs.forEach(bb => {
  // Filter out this bb from BBs
  const otherBBs = BBs.filter(other => other !== bb)

  // Check if any of the other BBs intersects with this bb
  otherBBs.forEach(other => {
    if (bb.intersectsBox(other)) {
      // Collision ! Do something
    }
  })
})  
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda