我正在尝试过滤碰撞,当圆形和多边形之间发生碰撞时,我能够过滤,但是我不知道如何向边缘形状添加固定装置(以及过滤器)...
我有一个带有四个栅栏的此类建筑(为简单起见,仅显示了一个,另外三个与第一个栅栏的定义相同)
class Building():
BUILDING_FILTER = b2Filter(categoryBits=BUILDING_CATEGORY,
maskBits=PEDESTRIAN_CATEGORY + CAR_CATEGORY,
groupIndex=BUILDING_GROUP,
)
def __init__(self, box2world, shape, position):
self.box2world = box2world
self.shape = shape
self.position = position
self.footprint = self.box2world.CreateStaticBody(position=position,
angle=0.0,
fixtures=b2FixtureDef(
shape=b2PolygonShape(box=(self.shape)),
density=1000,
friction=1000,
filter=Building.BUILDING_FILTER))
self.footprint.userData = {'obj': self}
###Creating pavements (fences)
# The coordinates which are passed to CreateEdgeChain have to be relative to the body.
# The position of the body is set when the object is constructed:
FENCE_OFFSET_VERTICAL = 1.15
FENCE_OFFSET_HORIZONTAL = 1.25
self.Lower_Fence = self.box2world.CreateStaticBody(position=(self.footprint.position[0], self.footprint.position[1] - FENCE_OFFSET_HORIZONTAL * self.shape[1]),\
filter=Building.BUILDING_FILTER) #Here is when the problem occurs
# And the edges have to be relative to this position rather than an absolute position:
self.Lower_Fence.CreateEdgeChain([(-self.shape[0], 0), (self.shape[0], 0)])
self.Lower_Fence.userData = {'obj': self}
我也尝试过
self.Lower_Fence = self.box2world.CreateStaticBody(position=(self.footprint.position[0], self.footprint.position[1] - FENCE_OFFSET_HORIZONTAL * self.shape[1]),\
fixtures=b2FixtureDef(filter=Building.BUILDING_FILTER)) #Here is when the problem occurs
# And the edges have to be relative to this position rather than an absolute position:
self.Lower_Fence.CreateEdgeChain([(-self.shape[0], 0), (self.shape[0], 0)])
self.Lower_Fence.userData = {'obj': self}
没有一个有效。 如何将滤镜附加到EdgeShape?谢谢