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

155
Visualizações
Problem on if else statement when working with raycasting

I am trying to use raycasting to detect whether my mouse pointed at the object, when it didnt touch the function is working fine, but when it touch, it did stop printing out "didnt touch", while it didnt print"touch" at the same time. For the if statement i include here, there is only 2 case either === or not right? so why my code isnt working? can anyone give me some help

function animate(){
    renderer.render(scene,camera);
    sLightHelper.update();
    rayCaster.setFromCamera(mousePosition,camera);
    var intersects = rayCaster.intersectObjects(scene.children);
    if ( house != undefined ){
        for(let i = 0; i < intersects.length; i++){
            if(intersects[0].object.id === house.ID){
                console.log("touch");
            }
            else{
                console.log("didnt touch");
            }
        }
        console.log("finished");
    }
    else{
        console.log('not ready')
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to write your code like so:

if ( intersects.length > 0 ) {
    for(let i = 0; i < intersects.length; i++){
        if(intersects[0].object.id === house.ID){
            console.log("touch");
        } else{
            console.log("didnt touch");
        }
    }
} else {
    console.log("didnt touch");
}
console.log("finished");
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