0

I always get this error message and I can´t get it away, can someone help?

AssertionError: The shape's body must be added to the space before (or at the same time) as the shape. the code that has the error (just a cutout of my project) just saying, I got pygmames and pymunk installed space = pymunk.Space() space.gravity = (0, -900) ground_body = pymunk.Body(body_type=pymunk.Body.STATIC) ground_shape = pymunk.Segment(ground_body, (0, 0), (SCREEN_WIDTH, 0), 5) space.add(ground_body, ground_shape) rope_body = pymunk.Body(body_type=pymunk.Body.KINEMATIC) rope_points = [(SCREEN_WIDTH // 2, SCREEN_HEIGHT), (SCREEN_WIDTH // 2, SCREEN_HEIGHT - ROPE_LENGTH)] rope_constraints = [] for i in range(len(rope_points) - 1): segment = pymunk.Segment(rope_body, rope_points[i], rope_points[i + 1], 5) segment.elasticity = 0.9 segment.friction = 0.5 segment.stiffness = ROPE_STIFFNESS space.add(segment) rope_constraints.append(segment) hope someone can help

4th Nov 2023, 10:14 PM
Marlon
1 Antwort
+ 1
Read the error message more carefully. The traceback tells you exactly which line of code is causing the error. And the AssertionError tells you that you must add the body to the shape first. Maybe something like space.add(rope_body) but could be also other places where this is a problem. https://stackoverflow.com/questions/69869718/assertionerror-the-shapes-body-must-be-added-to-the-space-before-or-at-the-sa
5th Nov 2023, 8:02 AM
Tibor Santa
Tibor Santa - avatar