Note that there are some explanatory texts on larger screens.

plurals
  1. POBounding box collision handling - not detection
    primarykey
    data
    text
    <p>I had this working a week ago, but then I ended up breaking it. I can't get it working again. I have some 2D sprites, they're just rectangles. No rotation involved. I'm not looking for a way to detect collisions between them, I have that, and there's thousands of articles out there about it. What I can't find is any resource about what to do when you see a collision. All I want is for the sprites to not be allowed to overlap. No bouncing or anything. They just stop. Specifically right now I just have a player and some level tiles that he runs into.</p> <p>It sounds simple, but it's not. It has to be very precise or weird things happen. I've been trying to fix this all day with strange mixed results. Sometimes my player gets stuck in the floor and can't move left or right. When I fix that, he can walk through blocks left or right.</p> <p>So my current setup thinks like this: Try moving the player where he wants to go. Then ask the map if his tile collides with anything. If so, the map says how many pixels of overlap there are in each of the four directions. The tricky part now is how the player should react to those numbers. When he's on the ground, there's a 1 pixel overlap with the floor, in order for him to know that he's on the ground (otherwise he vibrates between falling and landing on the ground, because without the overlap he thinks there's nothing below him). This one pixel overlap means that the left and right edges are also embedded in the floor and so he can't move.</p> <p>Is there a good method for getting everything sorted out, using one bounding box for the player? Would it be better to have a separate bounding box for each of his four sides?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload