0

I Tried to set up a simple ball that would fall using pymunk, but after two frames of running, the print statement outputs Vec2d(nan, nan), and the ball is no longer drawn to the screen.

import pymunk
import pygame

screen = pygame.display.set_mode((500,500))
space = pymunk.Space()
space.gravity = (0,9)

body = pymunk.Body(mass = 20,body_type = pymunk.Body.DYNAMIC)
shape = pymunk.Circle(body,25)
body.position = (250,250)

space.add(body,shape)

clock = pygame.time.Clock()
done = False
while not done:
    clock.tick(30)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    screen.fill((255,255,255))
    pygame.draw.circle(screen,(0,0,0),body.position,25)
    pygame.display.flip()
    
    print(body.position)
    space.step(1/50)

This is the code I wrote, which I expected would draw a ball which would fall off of the screen, but instead it appeared unmoving for two frames, before vanishing.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Bad
  • 1
  • 1

0 Answers0