Collision bug in player movement — not sure what's wrong
Hey everyone I’ve been working on a small 2D platformer using Pygame — just a personal project for now. Right now I’m trying to implement basic movement and collision with platforms. Most things are working, but for some reason my player keeps “sinking” slightly into the platform before stopping. It’s not a full-through fall, just 1–2 pixels inside. Been staring at this too long, maybe someone can spot what I’m missing. import pygame pygame.init() WIDTH, HEIGHT = 800, 600 win = pygame.display.set_mode((WIDTH, HEIGHT)) clock = pygame.time.Clock() player = pygame.Rect(100, 100, 50, 50) platform = pygame.Rect(0, 500, 800, 50) velocity_y = 0 gravity = 0.5 jump = -10 on_ground = False run = True while run: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() if keys[pygame.K_SPACE] and on_ground: velocity_y = jump velocity_y += gravity player.y += int(velocity_y) if player.colliderect(platform): player.bottom = platform.top velocity_y = 0 on_ground = True else: on_ground = False win.fill((30, 30, 30)) pygame.draw.rect(win, (0, 255, 0), platform) pygame.draw.rect(win, (255, 0, 0), player) pygame.display.update() Let me know if anything obvious jumps out!!!