Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!