允许特定物体与边缘碰撞但不与其他固定物体碰撞
Allowing specific bodies to collide with edges but not with other fixed bodies
我正在使用 edge-collision-detection 行为来添加与视口边缘的碰撞,并使用 body-impulse-response 行为来响应这些碰撞,因此碰撞体将从 "walls".
但是,我似乎无法使 body-impulse-response 仅适用于给定的物体和边缘(body-impulse-response 显然没有 applyTo 方法?),所以现在物体与其他固定物体发生碰撞身体虽然我也不想要。
我该如何解决这个问题?
谢谢!
我找到了一个可能的解决方案:
body-impulse-response 行为适用于给定通道中的所有冲突。
您可以更改报告碰撞的通道,并将该通道作为 body-impulse-response 行为的输入,而不是尝试将这种行为限制在特定的物体上。
(不完整)示例:
Phyiscs(function(world) {
var viewportBounds = Physics.aabb(0, 0, viewportWidth, viewportHeight);
world.add(Physics.behavior('edge-collision-detection', {
channel: 'collisions-edge:detected',
aabb: viewportBounds,
restitution: 0.7,
cof: 1
}));
world.add(Physics.behavior('body-impulse-response', {
check: 'collisions-edge:detected'
}));
/* You can now add a body-collision-detection behavior with the default
* collisions:detected (or a custom name) channel, and the
* body-impulse-response added above won't respond to these collisions.
*/
});
如果您有 different/better 解决方案 - 请分享!
我正在使用 edge-collision-detection 行为来添加与视口边缘的碰撞,并使用 body-impulse-response 行为来响应这些碰撞,因此碰撞体将从 "walls".
但是,我似乎无法使 body-impulse-response 仅适用于给定的物体和边缘(body-impulse-response 显然没有 applyTo 方法?),所以现在物体与其他固定物体发生碰撞身体虽然我也不想要。
我该如何解决这个问题?
谢谢!
我找到了一个可能的解决方案:
body-impulse-response 行为适用于给定通道中的所有冲突。 您可以更改报告碰撞的通道,并将该通道作为 body-impulse-response 行为的输入,而不是尝试将这种行为限制在特定的物体上。
(不完整)示例:
Phyiscs(function(world) {
var viewportBounds = Physics.aabb(0, 0, viewportWidth, viewportHeight);
world.add(Physics.behavior('edge-collision-detection', {
channel: 'collisions-edge:detected',
aabb: viewportBounds,
restitution: 0.7,
cof: 1
}));
world.add(Physics.behavior('body-impulse-response', {
check: 'collisions-edge:detected'
}));
/* You can now add a body-collision-detection behavior with the default
* collisions:detected (or a custom name) channel, and the
* body-impulse-response added above won't respond to these collisions.
*/
});
如果您有 different/better 解决方案 - 请分享!