my goal is to reproduce a top down physic system in which given two bodies B1 and B2, when B1 hits B2 then B2 oppose resistance and tries to get back to the initial position.
Something like this:
t = 0 B2 B1
t = 0 B2 B1
t = 0 B2 B1
t = 0 B2 B1
t = 0 B2B1
t = 0 B2B1
t = 0 B2B1
t = 0 B2B1
t = 0 B2B1
t = 0 B2B1
I managed to obtain this effect by connecting B2 with the initial position using a DampedSpring and the static body.
The code can be found at gist link
This is what the result of the code looks like
When the body becomes green then the DumpedSpring is added.
However there is one big issue. If I use DrawOptions to draw pymunk objects then I get the following error:
From cffi callback <function SpaceDebugDrawOptions.__init__.<locals>.f2 at 0x7f0540918f80>:
Traceback (most recent call last):
File "/home/michelangelo/miniconda3/envs/main/lib/python3.7/site-packages/pymunk/space_debug_draw_options.py", line 74, in f2
Vec2d._fromcffi(a), Vec2d._fromcffi(b), self._c(color))
File "/home/michelangelo/miniconda3/envs/main/lib/python3.7/site-packages/pymunk/pygame_util.py", line 124, in draw_segment
p1 = to_pygame(a, self.surface)
File "/home/michelangelo/miniconda3/envs/main/lib/python3.7/site-packages/pymunk/pygame_util.py", line 184, in to_pygame
return int(p[0]), surface.get_height()-int(p[1])
ValueError: cannot convert float NaN to integer
The error happens after the springs are apped to the space.
From what I understood from the Traceback the problem is that there is a body with Vec2d(Nan,Nan) position, however I am not able to properly debug this problem.
Am I doing something wrong or is it a bug in the package? Am I using DumpedSpring in a way it should not be used? If so, do yyou have any alternative suggestion?
Thank you very much!
Kind regards, Michelangelo