在 RealityKit 中,我怎样才能创造一个没有摩擦的世界?

Within RealityKit, how can I make the world without friction?

我想让物理世界没有摩擦和阻尼。

我试过把场景的重力设为(0,0,0),做成方块和球,点击的时候给力。我想让球永远运动,但它只是在某个时候停止。

如何使实体摩擦力为零?

将新的 Physics Material 应用到您的模型实体。

为此使用 generate(friction:restitution:) type method:

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)

P.S。由于 RealityKit 中物理引擎的一些不完善,我想不可能创建一个永恒的弹跳。看来 RealityKit 的下一次更新将修复物理引擎的缺陷。