简体   繁体   中英

Simultaneous rotation of segments in pygame

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM