【问题标题】:collision detection how to NOT check if player is standing on foreground tile碰撞检测如何不检查玩家是否站在前景瓷砖上
【发布时间】:2014-03-15 15:24:02
【问题描述】:

碰撞检测检查玩家是否与前景相交:

    if (rbot2.intersects(r) && type == 8) {
        System.out.println("Collision With Foreground");
    }

现在,一旦您不再站在这片前景上,我需要玩家跌倒。但是我如何检测没有站在前台?

我试过了:

if (rbot2.intersects(r) && type == 8) {
  System.out.println("Collision With Foreground");
}
else
  System.out.println("No longer colliding with Foreground");

但是这样做的结果是无论你站在哪里,输出都是 ALWAYS:不再与 Foreground 碰撞。

我在这里做错了什么?

【问题讨论】:

    标签: collision detection


    【解决方案1】:
    if (rbot2.intersects(r) && type == 8) {
      System.out.println("Collision With Foreground");
    }
    else
      System.out.println("No longer colliding with Foreground");
    

    翻译成

    if (rbot2.intersects(r) && type == 8) {
      System.out.println("Collision With Foreground");
    }
    
    if((!rbot2.intersects(r)) || (type != 8))
      System.out.println("No longer colliding with Foreground"); //probably valid always
    

    您偶然发现了“对于所有其他可能的情况 - 打印“不再碰撞...”场景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多