libgdx 与线和多边形的碰撞(相交)
libgdx collision with line and polygon (Intersector)
我的 libgdx
游戏有激光,我想知道光束是否击中目标。
我在函数 (总是为真) 上遇到了一些问题,所以我做了一个非常简单的测试,我仍然为真!
我是不是漏掉了什么?
为什么这个函数返回 true?
if(Intersector.intersectLinePolygon(new Vector2(100, 100), new Vector2(200, 100), new Polygon(new float[] {0, 0, 5, 0, 5, 5}))) {
System.out.println("true");
}
提前致谢!
我也是第一次用Intersector的时候就被这个坑了
intersectLinePolygon()
方法适用于无限延伸的直线,而不仅仅是您指定的两点之间。
使用 intersectSegmentPolygon()
方法来完成你想要的...
if(Intersector.intersectSegmentPolygon(new Vector2(100, 100), new Vector2(200, 100), new Polygon(new float[] {0, 0, 5, 0, 5, 5}))) {
System.out.println("true");
}
我的 libgdx
游戏有激光,我想知道光束是否击中目标。
我在函数 (总是为真) 上遇到了一些问题,所以我做了一个非常简单的测试,我仍然为真!
我是不是漏掉了什么?
为什么这个函数返回 true?
if(Intersector.intersectLinePolygon(new Vector2(100, 100), new Vector2(200, 100), new Polygon(new float[] {0, 0, 5, 0, 5, 5}))) {
System.out.println("true");
}
提前致谢!
我也是第一次用Intersector的时候就被这个坑了
intersectLinePolygon()
方法适用于无限延伸的直线,而不仅仅是您指定的两点之间。
使用 intersectSegmentPolygon()
方法来完成你想要的...
if(Intersector.intersectSegmentPolygon(new Vector2(100, 100), new Vector2(200, 100), new Polygon(new float[] {0, 0, 5, 0, 5, 5}))) {
System.out.println("true");
}