微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/iOS/333480.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐