1

In pymunk, I set the body mass and the space gravity, it should automatic fall down, but the body with segment shape do not move, here is my code in pyglet

import pyglet
import pymunk
from pymunk.pyglet_util import DrawOptions

window = pyglet.window.Window(1280,720,resizable=False)
options = DrawOptions()

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

ball_mass = 1
ball_radius = 10

ball_moment = pymunk.moment_for_circle(ball_mass,0,10)
ball = pymunk.Body(ball_mass,ball_moment)
ball_shape = pymunk.Circle(ball,ball_radius)
ball.position =200,500
ball_shape.elasticity = 1
ball_shape.friction = 1

space.add(ball,ball_shape)

stick = pymunk.Body(1,100,body_type=pymunk.Body.DYNAMIC)
stick_shape = pymunk.Segment(stick,(0,0),(150,150),4)
stick.position = (300,400)
pin = pymunk.PivotJoint(space.static_body,stick,(300,400))
# stick.apply_impulse_at_local_point((0,-100),(150,150))
space.add(stick,stick_shape,pin)


@window.event
def on_draw():
    window.clear()
    space.debug_draw(options)

def update(dt):
    space.step(dt)


if __name__ == '__main__':
    pyglet.clock.schedule_interval(update, 1/60.0)
    pyglet.app.run()

the ball fall down but the stick do not move, or apply_impulse_at_local_point on stick, I just wondering, if there is no PivotJoint, the stick fall down, I just pin one point of the stick, why it does not move, it should rotate, is it?

I_love_vegetables
  • 1,575
  • 5
  • 12
  • 26
xmzhang
  • 79
  • 1

1 Answers1

0

One problem is that the stick has its center of gravity at one end. That make it behave a bit strange. Try making it have its center of gravity in its actual center instead.

stick_shape = pymunk.Segment(stick,(-75,-75),(75,75),4)
viblo
  • 4,159
  • 4
  • 20
  • 28