1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Are there any simple collision resolution algorithms?

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I am make a top-down point and click game in Python/Raylib that involves no gravity and I'm using a procedurally generated tile map approach to build the world. With my current collision resolution algorithm, when my player collides with 2 flush aabb's or more at an angle, my player gets caught on the edge an walks through it. This is due to the order that I check which sides of an aabb I collided and resolved with.

    I'm trying to brain storm a simple algorithm to resolve collision between a dynamic (the player) and multiple static axis-aligned bounding boxes (walls), but I can't seem to see through to the end of it though. Just curious to hear what others have done.

    I was expecting to see my player glide across a group of flush aabb's, but it isn't the case.

    Here is my collision algorithm.

    locsize is location / size of the player, stored as a Rectangle prev_locsize is the previous location of the player so I can tell where the player was before it collided

    def collision(self, collidable_objects):
    for object in collidable_objects:
    if raylib.CheckCollisionRecs(self.locsize, object):
    # Left
    if self.prev_locsize.x + self.prev_locsize.width <= object.x:
    self.locsize.x = object.x - self.locsize.width
    return
    # Right
    if self.prev_locsize.x >= object.x + object.width:
    self.locsize.x = object.x + object.width
    return
    # Top
    if self.prev_locsize.y + self.prev_locsize.height <= object.y:
    self.locsize.y = object.y - self.locsize.height
    return
    # Bottom
    if self.prev_locsize.y >= object.y + object.height:
    self.locsize.y = object.y + object.height

    Continue reading...

Compartilhe esta Página