我有几个碰撞设置在我的应用程序中完美运行但是我不能在我的生活中得到最后2个碰撞在同一节点上工作。
这就是我所拥有的:
alien.physicsBody!.contactTestBitMask = ColliderType.object.rawValue
alien.physicsBody!.categoryBitMask = ColliderType.object.rawValue | ColliderType.torp.rawValue
alien.physicsBody!.collisionBitMask = ColliderType.object.rawValue
ship.physicsBody!.contactTestBitMask = ColliderType.ship.rawValue | ColliderType.object.rawValue
ship.physicsBody!.categoryBitMask = ColliderType.ship.rawValue
ship.physicsBody!.collisionBitMask = ColliderType.ship.rawValue
torpedoNode.physicsBody!.contactTestBitMask = ColliderType.torp.rawValue
torpedoNode.physicsBody!.categoryBitMask = ColliderType.torp.rawValue
torpedoNode.physicsBody!.collisionBitMask = ColliderType.torp.rawValue
由于代码在上面,torp与外星人接触。但是,该船不与外国人联系。
如果我从外星人categoryBitMask中删除“ColliderType.torp.rawValue”,那么船只会联系外国人,但是torp不会联系该船。
对于与外国人联系的船,我使用:
if contact.bodyA.categoryBitMask == ColliderType.object.rawValue || contact.bodyB.categoryBitMask == ColliderType.object.rawValue
为了让torp联系外星人我使用:
if contact.bodyA.categoryBitMask == ColliderType.torp.rawValue || contact.bodyB.categoryBitMask == ColliderType.torp.rawValue {
我怎样才能同时工作?!我已经度过了几天而无法理解它。
我可以完美地工作,而不是两者在一起。
答案 0 :(得分:1)
对于任何有同样问题的人,在这种情况下@Alex Ingram希望外星人与船只和鱼雷发生碰撞,这是帮助他的解决方案。
> str(x)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 691231 obs. of 31 variables:
$ A : chr "2011-12-06 00:00:00" "2011-03-11 00:00:00" "2014-11-17 00:00:00" "2013-01-07 15:19:02" ...
$ B : num 6 6 11 11 6 6 6 6 6 6 ...
$ C : num NA NA NA NA NA NA NA NA NA NA ...
$ D : chr "2016-01-01 00:00:00" "2016-01-01 00:00:00" "2016-01-01 00:00:00" "2016-01-01 00:00:00" ...
$ E : chr NA NA NA NA ...
$ F : num 0 230 230 230 230 230 230 230 230 0 ...
$ G : num 13 35 38 128 12 6 10 4 2 6 ...
$ H : chr NA NA NA NA ...
$ J : chr "35" "35" "28" "34" ...
$ K : num 0 63 32 63 40 40 35 40 35 25 ...
$ L : num 3 3 3 3 3 3 3 2 2 2 ...
$ M : num 301 301 301 301 301 301 301 301 301 301 ...
$ N : chr "613.0" "9630.0" "9114.0" "600.0" ...
$ O : chr "000356039" "000664676" "000770082" "000617804" ...
$ P : chr "11610000" "0000003001" "1161000" "43850" ...
$ Q : num 10089 10089 10972 27629 27630 ...
$ R : num 7.07e+17 7.07e+17 7.07e+17 7.07e+17 7.07e+17 ...
$ S : num 1 1 1 1 1 1 1 1 1 1 ...
$ T : chr "XX" "XX" "809" "96" ...
$ U : chr "cac" "edr" "ssr" "nsk" ...
$ V : chr "1954-05-17 00:00:00" "1973-05-17 00:00:00" "1997-06-24 00:00:00" "1976-12-24 00:00:00" ...
$ W : num 287 287 287 665 664 664 664 664 664 664 ...
$ X : num 1 1 1 1 1 1 1 1 1 1 ...
$ Y : num NA NA NA NA NA NA NA NA NA NA ...
$ Z : num 24828 39591 8932 35162 28540 ...
$ AA : chr "0001" "0001" "0001" "0002" ...
$ AB : chr "0001-TRA" "0001-TRB" "0001-TRC" "0002-TRD" ...
$ AC : chr "0,230" "0,230" "0,230" "0,230" ...
$ AD : chr "K03" "K03" "K03" "K05" ...
$ AE : num 3 3 3 3 3 3 3 3 3 3 ...
$ AF : chr "IT" "IT" "IT" "IT" ...
> str(y)
'data.frame': 691231 obs. of 1 variable:
$ fault: num 0 0 0 0 0 0 0 0 0 0 ...
然后,在alien.physicsBody!.contactTestBitMask = ColliderType.ship.rawValue | ColliderType.torp.rawValue
alien.physicsBody!.categoryBitMask = ColliderType.object.rawValue //Im assuming this is his alien's BitMask
alien.physicsBody!.collisionBitMask = none
中,他必须写下以下内容
didBeginContact