在Pymunk中,当我旋转身体时,它的形状不会旋转。当我施加脉冲时,形状会按预期同步移动。我的谷歌搜索表明,当身体旋转时,身体的形状应该是旋转的。我是否从根本上误解了轮换?
以下是相关的轮换代码:
def selectEntity(self, location):
shapes = self.space.point_query(location)
bodies = set()
for shape in shapes:
bodies.add(shape.body)
for body in bodies:
body.angle += 1.57079633 # + 90 degrees
这是初始化代码:
def _addShip(self, mass, center, angle = 0.):
radius = 10
groupId = self.getNextBodyId() # shapes in the same group do not generate collisions
body = pymunk.Body(mass, pymunk.moment_for_circle(mass, radius / 10, radius)) # mass, inner radius, outer radius, offset
body.angle = angle
partOne = pymunk.Circle(body, radius, center)
partOne.group = groupId
partOne.color = THECOLORS['blue']
partOne.friction = .8
partTwo = pymunk.Circle(body, radius, (center[0], center[1] + 20))
partTwo.group = groupId
partTwo.color = THECOLORS['blue']
partTwo.friction = .8
ship = (partOne, partTwo, body)
self.space.add(*ship)
答案 0 :(得分:0)
碰撞树/哈希不会立即更新,您需要先向前迈出空间。更新碰撞数据的另一种方法是调用Space.reindex_shape(shape_that_has_been_moved)。
参见此示例:
>>> from pymunk import *
>>> s = Space()
>>> b = Body(1,1)
>>> c1 = Circle(b, 10, (-10,0))
>>> c2 = Circle(b, 10, (10,0))
>>> s.add(b,c1,c2)
>>> s.step(.1)
>>> s.point_query((-15,0))
[<pymunk.Circle object at 0x02264690>]
>>> b.angle
0.0
>>> b.angle = 1.57
>>> s.point_query((-15,0))
[<pymunk.Circle object at 0x02264690>]
>>> s.step(.1)
>>> s.point_query((-15,0))
[]
>>> s.point_query((0,-15))
[<pymunk.Circle object at 0x02264690>]
>>> b.angle = 0
>>> s.point_query((-15,0))
[]
>>> s.reindex_shape(c1)
>>> s.reindex_shape(c2)
>>> s.point_query((-15,0))
[<pymunk.Circle object at 0x02264690>]