ios – SceneKit碰撞偶尔会失败

我正在尝试模拟足球比赛.我有一个模拟球场的SCNPlane.我已经导入了足球目标3d模型(.dae文件)和球模型(.dae).

我的球有一个动态的物理身体,飞机静止,目标是运动学.我为每个SCNNode设置了categoryBitMask和contactTestBitMask.

当我将球射向球门时,有时球会反弹并且表现得如预期的那样,但有时候球会穿过球门并穿过它.

我还指定了SCNPhysicsContactDelegate,并且当球再次反弹时触发了didBeginContact,但是当球越过它时,则不会调用该方法.

你知道会发生什么吗?

谢谢!

解决方法

实例属性categoryBitMask定义物理主体所属的类别,contactTestBitMask定义哪些类别的主体导致与此物理主体的交集通知.

您需要一个collisionBitMask实例属性,该属性定义哪些类别的物理实体可以与此物理实体发生冲突.

var collisionBitMask: Int { get set }

When two physics bodies contact each other,a collision may occur. SceneKit compares the body’s collision mask to the other body’s category mask by performing a bitwise AND operation. If the result is a nonzero value,then the body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example,you might choose to avoid collision calculations that would make negligible changes to a body’s velocity.
The default value is all (a bit mask whose every bit is enabled),specifying that the body will collide with bodies of all other categories.

static var all: SCNPhysicsCollisionCategory { get }

all is default Type Property for a physics body’s collisionBitMask property.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...