2

I have been trying to create a game in pymunk with a 2D terrain using Opennoise. The coordinates of the terrain are:

from opensimplex import OpenSimplex
noise = OpenSimplex()
inputs = np.zeros((100002,2))

for x in range(100000):
    inputs[x] = ([x, (noise.noise2d(0.004*x, 0) - 0.125)*100 + 700])
inputs[100000] = ([100000,900])
inputs[100001] = ([0,900])

The y coordinates are shifted by +700 because i use pygame to display everything and the top of the window is at y = 0 and the bottom at y = 800.

I then create a pymunk static body with a polygon shape, and create a pygame shape to display the terrain like this: (pm = pymunk)

 self.body = pm.Body(10,100,pm.Body.STATIC)
 self.shape = pm.Poly(self.body, inputs)
 space.add(self.body, self.shape)
 pygame.draw.polygon(surface, color, inputs)

The shape created by pygame, which looks correct, doesnt match up with the shape of the pymunk polygon which indicates that pymunk is not creating the intended shape. So how do i create the the pymunk shape as intended?

lars.stifi
  • 23
  • 3

1 Answers1

0

I think the problem might be that the polygon is not closed and convex. Usually if you want a long "wave" / "line" its easier to use segment shapes instead of polygons. Pymunk polygons will always be convex. If what you pass in as coordinates are not already convex and closed a convex hull will be created and used.

IF this is not the problem I think it would help to understand the problem if you reduced the length of the polygon to maybe 10 or 100, and take a screenshot or two that shows the problem and put it here.

viblo
  • 4,159
  • 4
  • 20
  • 28