How can I rotate a segment connected to another segment but limiting the angle of rotation. So, for example, if I have a static segment and another dynamic segment connected with a Pivot Joint and rotating around with a Simple Motor. The motor does a whole revolution, but I only want the dynamic segment to move from a certain point to another back and forth continuously. My goal is to make a walking animal and move the legs back and forth. How can I achieve that ?
This is what I have now :
seg1= Segment((100, 100), (100, 200), 10, True, True, (0, 255, 0, 0)) # density=10, static, filter, green
seg2= Segment((100, 200), (100, 300), 10, False, True, (255, 0, 0, 0)) # dynamic, filer, red
PivotJoint(seg1.body, seg2.body, (100, 200), (100, 200))
SimpleMotor(seg1.body, seg2.body, 1)
RotaryLimitJoint(seg1.body, seg2.body, -pi, pi)
Here, I would want the seg2 to go from (0, 200) to (200, 200) back and forth. I know changing the rate to negative will rotate the segment backwards but it doesn't seem to change when I do this in the draw() function like this :
def draw(self):
self.screen.fill(GRAY)
space.debug_draw(self.draw_options)
pygame.display.update()
self.rate = self.rate*(-1) # going from 1 to -1 continuously
self.motor.rate = self.rate
text = f'fpg: {self.clock.get_fps():.1f}'
pygame.display.set_caption(text)