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.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...