ios – SceneKit碰撞偶尔会失败

前端之家收集整理的这篇文章主要介绍了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相关文章