在我的游戏世界中,每个人都有附有传感器形状的固定装置。当我进行光线投射时,它会击中这些灯具,但我只想击中具有至少一种不是传感器的形状的灯具。这可能吗?
我正在使用Box2dx - C# 端口。
另外,回调有什么作用?
world.PhysicsWorld.RayCast((f, p, n, fr) =>
{
fixture = f;
position = p;
return fr;
}, point1, point2);
这是我正在调用的光线投射功能。文档说回调可用于指定要返回的形状数量,但我不知道如何做到这一点:
/// Ray-cast the world for all fixtures in the path of the ray. Your callback
/// controls whether you get the closest point, any point, or n-points.
/// The ray-cast ignores shapes that contain the starting point.
/// @param callback a user implemented callback class.
/// @param point1 the ray starting point
/// @param point2 the ray ending point
public void RayCast(Func<Fixture, Vector2, Vector2, float, float> callback, Vector2 point1, Vector2 point2)
{
RayCastInput input = new RayCastInput();
input.maxFraction = 1.0f;
input.p1 = point1;
input.p2 = point2;
_rayCastCallback = callback;
_contactManager._broadPhase.RayCast(_rayCastCallbackWrapper, ref input);
_rayCastCallback = null;
}