2021-01-31

Pygame Collision Keeps Teleporting My Player How To Fix?

I am not sure why but when I press the right key and then press the left key while moving my player it will glitch it throw the rectangle VIDEO it works perfectly the other way around but it will keep doing that if I hold right key and then click left key while holding the right key it will teleport me throw the block I am not sure how to fix this at all any help is appreciated! VIDEO < another video of the problem

my collisions for the sides

    # sides for player and player screen movement
    platform_rect_list = [p.rect for p in collids]
    player_rect = playerman.get_rect()
    player_rect.topleft = (px, py)

    playerman.y = py
    if player_rect.collidelist(platform_rect_list) < 0:
        playerman.x = px

    move_right = keys[pygame.K_RIGHT]
    move_left = keys[pygame.K_LEFT]
    if move_right:
        base1.x -= playerman.speed
        base2.x -= playerman.speed
        base3.x -= playerman.speed
        base4.x -= playerman.speed
        base5.x -= playerman.speed
        base6.x -= playerman.speed
        crate1.x -= playerman.speed
        base44.x -= playerman.speed
        end1.x -= playerman.speed
        base45.x -= playerman.speed
        stopmove1.x -= playerman.speed
        text_show_collision.x -= playerman.speed
        text1.x -= playerman.speed
        rop1.x -= playerman.speed
        text22.x -= playerman.speed
        text_show_collision2.x -= playerman.speed
        portal1.x -= playerman.speed
        base46.x -= playerman.speed
        for shot in shots:
            shot.x -= playerman.speed
        
        for collid in collids:
            collid.x -= playerman.speed
            

    if move_left:
         base1.x += playerman.speed
         base2.x += playerman.speed
         base3.x += playerman.speed
         base4.x += playerman.speed
         base5.x += playerman.speed
         base6.x += playerman.speed
         crate1.x += playerman.speed
         base44.x += playerman.speed
         end1.x += playerman.speed
         base45.x += playerman.speed
         stopmove1.x += playerman.speed
         text_show_collision.x += playerman.speed
         text1.x += playerman.speed
         rop1.x += playerman.speed
         text22.x += playerman.speed
         text_show_collision2.x += playerman.speed
         portal1.x += playerman.speed
         base46.x += playerman.speed

         for shot in shots:
            shot.x += playerman.speed
         for collid in collids:
            collid.x += playerman.speed




            

    platform_rect_list = [p.get_rect() for p in collids] # get_rect()
    player_rect = playerman.get_rect()
    player_rect.topleft = (px, py)

    playerman.y = py
    cI = player_rect.collidelist(platform_rect_list)
    if cI >= 0:
        # undo movement of platforms dependent on the direction and intersection distance
        dx = 0
        if move_right: 
            dx = platform_rect_list[cI].left - player_rect.right
        if move_left:
            dx = platform_rect_list[cI].right - player_rect.left

        for collid in collids:
            collid.x -= dx
            collid.get_rect() # update rectangle

        base1.x -= dx
        base2.x -= dx
        base3.x -= dx
        base4.x -= dx
        base5.x -= dx
        base6.x -= dx
        crate1.x -= dx
        base44.x -= dx
        end1.x -= dx
        base45.x -= dx
        stopmove1.x -= dx
        text_show_collision.x -= dx
        text1.x -= dx
        rop1.x -= dx
        text22.x -= dx
        text_show_collision2.x -= dx
        portal1.x -= dx
        base46.x -= dx
        for shot in shots:
            shot.x -= dx
        



from Recent Questions - Stack Overflow https://ift.tt/3agrlYZ
https://ift.tt/eA8V8J

No comments:

Post a Comment