Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda