在pymunk中,我设置了体重和空间重力,它会自动掉落,但是具有段形状的身体不会移动,这是我在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()
球掉下来但棒不动,或者在棒上套上apply_impulse_at_local_point,我只是想知道,如果没有PivotJoint,棒会掉下来,我只是将棒的一点固定,为什么它不动,应该旋转吗?
答案 0 :(得分:0)
一个问题是杆的一端有重心。这使它的行为有些奇怪。尝试使其重心位于其实际中心。
stick_shape = pymunk.Segment(stick,(-75,-75),(75,75),4)