SFML community forums

Help => Graphics => Topic started by: Jan666 on August 09, 2022, 12:26:15 am

Title: Collision Opposite Side
Post by: Jan666 on August 09, 2022, 12:26:15 am
Hey,
I have a question, the collision  between playerBounds and WallBounds works very good, but on the opposite Side not,  can somebody Tell me why?
 if(playerBounds.intersects(wallBounds)){
                       
        // Left Collision
 if (playerBounds.left < wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
         {
         
          player.setPosition(playerBounds.left, wallBounds.top - playerBounds.height);
          }
         
 
          // Boton Collision not working yet
 if( playerBounds.left >wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
          {
               
                player.setPosition(playerBounds.left, wallBounds.top - wallBounds.height);
            }  

 
Title: Re: Collision Opposite Side
Post by: eXpl0it3r on August 15, 2022, 04:52:52 pm
I assume, you'd have to reset the position to left + width and not just left.

For such math-y things, I suggest to either set a break point and check the values with a debugger, or print the values to the console, so you can understand what's going on.
Additionally, it can help to draw things out on paper.