Collision decetion and solution

by over_stack   Last Updated August 13, 2019 15:13 PM

I am making my own game engine on Python and I got stuck with collision between objects. `

If we go Right

        if (collision_rect.right >= object_collision_rect.left) and \
                (collision_rect.left <= object_collision_rect.left):
            if (collision_rect.bottom > object_collision_rect.top) and \
                    (collision_rect.top < object_collision_rect.bottom):
                if self.acceleration.x > 0:
                    self.acceleration.x = 0
                    moving.x = object_collision_rect.left - collision_rect.right

`

Bottom

        if (collision_rect.bottom >= object_collision_rect.top) and \
                (collision_rect.top <= object_collision_rect.top):
            if (collision_rect.right > object_collision_rect.left) and \
                    (collision_rect.left < object_collision_rect.right):
                if self.acceleration.y > 0:
                    self.acceleration.y = 0
                    moving.y = object_collision_rect.top - collision_rect.bottom

There are 2 more for left and top. It makes teleporting on corners. And if we change the second conditions from < > to <= >=, we get teleporting on edges, if we have acceleration x and y both != 0



Related Questions


Updated August 02, 2017 13:13 PM

Updated September 25, 2017 13:13 PM

Updated May 25, 2015 22:05 PM

Updated March 02, 2018 22:13 PM

Updated July 23, 2015 13:05 PM