【问题标题】:libgdx collision with line and polygon (Intersector)libgdx 与线和多边形的碰撞(相交)
【发布时间】:2016-06-21 11:41:41
【问题描述】:

我的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");
}

提前致谢!

【问题讨论】:

    标签: java libgdx collision-detection intersection


    【解决方案1】:

    当我第一次使用 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");
    }
    

    【讨论】:

    • 谢谢!这解决了问题,我得到了这些函数之间的区别,但它不会仍然是错误的,因为即使有一条无限线,它也不会在我的示例中相交?
    • 它将相交于 (0, 0)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多