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

173
Visualizações
Checking intersection between two rectangles - Javascript

I am making a simple in-browser maze game using HTML and Javascript (Canvas), and am trying to make a function which will return true if the player's hitbox intersects with one of the maze walls. t is the player hitbox, r is one of the maze walls (they all get passed into this function one by one). For both rectangles, x1 and y1 represent the top left corner, and x4 and y4 represent the bottom right corner (x+width and y+height). This function returns true even when the player hitbox is clearly not intersecting with anything. What can I fix here?

function detectCollision(t,r) {
        intersection = true;
        
        //check if no horizontal overlap
        if ((t.x1 > r.x4) || (r.x1 > t.x4)) {
            intersection = false;
            }
        //vertical overlap
        if ((t.y1 > r.y4) || (r.y1 > t.y4)) {
            intersection = false;
            }
about 4 years ago · Juan Pablo Isaza
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