Simultaneous rotation of segments in pygame

166 views Asked by At

How to make a boxed segment rotate, with constant angular velocity, about its combined center of mass (400,263.5) in pygame. The goal is to simultaneously rotate the four segments such that the boxed segment rotates as a unit while a dynamic body moves in it under the influence of gravity

1

There are 1 answers

6
viblo On

If you want the segments attached to each other all the time the easiest solution is to attach all 4 of them to the same body, and then rotate that body. To make it easy to figure out the actual rotation set the body position to the center (400,263.5), and adjust the segment endpoints to be relative to this point.

Something like this:

pts = [(-27, -238.5), (27,-238.5), (27,238.5), (-27,238.5)]
body_type=pymunk.Body(body_type=pymunk.Body.KINEMATIC)  
body_type.position = (400, 263.5)  
space.add(body_type)
for i in range(4):
    segment = pymunk.Segment(body_type, pts[i], pts[(i+1)%4], 2)
    segment.elasticity = 0
    segment.friction=0
    space.add(segment)