I'm working on a simples 2D top-down game and I started using Pymunk to handle physics.
I've created a GameObject class that contains basically a pymunk.Body, a pymunk.Shape and a pygame.Surface.
Here is the code part were everything goes wrong
player = GameObject([-1, 0], [1, 1], (46, 150, 80))
obj = GameObject([1, 0], [1, 1], (255, 255, 255))
SPACE.add(player.getBody(), player.getShape())
SPACE.add(obj.getBody(), obj.getShape())
while True:
CLOCK.tick(FPS)
SPACE.step(1/FPS)
for event in pygame.event.get():
eventHandler(event)
player.setPosition([.2, 0], True)
print(player.getPosition())
Well, using VSCode debugging i saw that in the second iteration of the while True:
, after SPACE.step(1/FPS)
, all my Vec2d, that are associated with the position of the bodies, becomes NaN.
So my player.getPosition()
returns Vec2d(NaN, NaN)
and the object disapears (in the rendering stage, cuz well, there's no position to render it :) ).
Anyone knows why SPACE.step
is destroying every thing?
Thx