3

I'm trying to add a box to a space, here's what I have:

body = pymunk.Body()
body.position = 300, 200
box = pymunk.Poly.create_box(body, (100, 300))
space.add(body, box)

I get the following error:

  File "C:\Users\Home\AppData\Roaming\Python\Python36\site-packages\pymunk\pygame_util.py", line 153, in <listcomp>
    ps = [to_pygame(v, self.surface) for v in verts]
  File "C:\Users\Home\AppData\Roaming\Python\Python36\site-packages\pymunk\pygame_util.py", line 183, in to_pygame
    return int(p[0]), surface.get_height()-int(p[1])
ValueError: cannot convert float NaN to integer

If I do not add the body in space.add, I don't get the error, but then it doesn't behave properly.

It seems p[ ] is a vertex, but since I'm using create_box, I'm not specifying any vertices.

I'm very new to pymunk, and mostly new to python, so it's likely something very simple, but I've been at it for several hours and can't crack it.

Ivan
  • 34,531
  • 8
  • 55
  • 100
GTS
  • 71
  • 3

1 Answers1

4

Looks like I needed to add a moment to the body, this solved the problem. I previously had a mass and no moment, assuming that defaulting to value 0 as shown in the documentation would not be problematic.

GTS
  • 71
  • 3