swift - 在 RealityKit 中,我怎样才能让世界没有摩擦?
解决方案
将新的应用Physics Material
到您的模型实体。
对于这种使用generate(friction:restitution:)
类型方法:
static func generate(friction: Float = 0,
restitution: Float = 0) -> PhysicsMaterialResource
在哪里
/* the coefficient of friction is in the range [0, infinity] */
/* and the coefficient of restitution is in the range [0, 1] */
这是一个代码:
arView.environment.background = .color(.darkGray)
let mesh = MeshResource.generateSphere(radius: 0.5)
let material = SimpleMaterial()
let model = ModelEntity(mesh: mesh,
materials: [material]) as (ModelEntity & HasPhysics)
let physicsResource: PhysicsMaterialResource = .generate(friction: 0,
restitution: 0)
model.components[PhysicsBodyComponent] = PhysicsBodyComponent(
shapes: [.generateSphere(radius: 0.51)],
mass: 20, // in kilograms
material: physicsResource,
mode: .dynamic)
model.generateCollisionShapes(recursive: true)
let anchor = AnchorEntity()
anchor.addChild(model)
arView.scene.anchors.append(anchor)
PS由于RealityKit中物理引擎的一些不完善,我想不可能创造一个永恒的弹跳。似乎下一个 RealityKit 的更新将修复物理引擎的缺陷。
推荐阅读
- objective-c - 计算协调火星时间
- c++ - Xcode Test Navigator 如何在纯 C++ 项目中显示 Google 测试
- python - 刮 NSE 页面的技巧是什么?
- java - Android(Java)在json中搜索字符串
- node.js - Kubernetes HPA 部署找不到目标资源
- python - 无法导入解析 tfrecords 序列化示例
- javascript - 将 MSAL.js 用于 NodeJ
- python - 在 sci-kit 中保存和加载模型优化
- angular - Angular 7 innerHTML using a material design button
- ocaml - 如何将 Mccs/Clingo 定义为 OPAM 求解器而不是 aspcud