【问题标题】:swift usesPreciseCollisionDetection does not work?swift usesPreciseCollisionDetection 不起作用?
【发布时间】:2016-08-23 14:52:29
【问题描述】:

我制作了一个应用程序,您需要在其中向敌人射击,但有时子弹会穿过敌人。 swift sprite kit game when I shoot on a enemy sometimes the bullet goes trough the enemy, how can I fix this?

所以我添加了usesPreciseCollisionDetection = true。 但子弹有时仍会穿过敌人。所以我的问题是我做错了什么还是 usesPreciseCollisionDetection 不起作用?

感谢您阅读我的问题,希望有人可以帮助我。

【问题讨论】:

  • 这两个物体应该碰撞、接触还是两者兼而有之?
  • 我做到了,如果子弹击中敌人,敌人就会爆炸并移除子弹

标签: swift sprite-kit detection skphysicsbody


【解决方案1】:

您正在使用 moveTo 移动子弹,物理引擎无法以您想要的方式与 moveTo 一起使用,usesPreciseCollisionDetection 不会做任何事情

就你的物理世界而言,你的子弹是静止的。你只是在扮演上帝并执行某种分子运输来移动物品。

你需要使用像applyImpulse这样的函数,或者如果你想让它正常工作,甚至只是给physicsBody一个速度

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,即使将 usesPreciseCollisionDetection 设置为 true 并且 SKPhysicsBody 都是矩形,有时也无法检测到碰撞。在我的情况下,由于某种原因,当我将 SKPhysicsBody 之一更改为圆形而不是矩形时,usesPreciseCollisionDetection 开始工作得更好。尝试将您的子弹物理体更改为圆形,似乎带有圆形的碰撞检测算法更精确,因此可能会对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-08-26
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多