0
import pymunk

space = pymunk.Space()
space.gravity = (0, -100)

body = pymunk.Body(body_type=pymunk.Body.DYNAMIC)
body.mass = 1
body.moment = pymunk.moment_for_box(body.mass, (100, 100))
shape = pymunk.Poly.create_box(body, (100, 100), 0)
space.add(body, shape)

for i in range(100):

print("center of gravity={0}\nposition ={1}\n".format(
    body.center_of_gravity, body.position))
space.step(0.5)

The result is like this center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, 0.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, 0.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -25.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -75.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -150.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -250.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -375.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -525.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -700.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -900.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -1125.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -1375.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -1650.0)

center of gravity = Vec2d(0.0, 0.0) position = Vec2d(0.0, -1950.0)

. . .

What is the problem with center_of_gravity??

Dooly
  • 1
  • 1

1 Answers1

0

Center of gravity is in body local coordinates, as described here http://www.pymunk.org/en/latest/pymunk.html#pymunk.Body.center_of_gravity So it tells you how the center of gravity is offset relative to the body position. To get it in world coordinates you take the center of gravity and add the body position.

viblo
  • 4,159
  • 4
  • 20
  • 28