Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Collision Opposite Side  (Read 1352 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Collision Opposite Side
« 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);
            }  

 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Collision Opposite Side
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/