首页 > 解决方案 > 在 RealityKit 中,我怎样才能让世界没有摩擦?

问题描述

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

我试图使场景的重力为(0,0,0),并制作一个正方形和球,在点击时给予力量。我想让球永远移动,但它只是在一段时间后停止。

如何使实体摩擦为零?

在此处输入图像描述

标签: swiftaugmented-realityarkitrealitykit

解决方案


将新的应用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 的更新将修复物理引擎的缺陷。


推荐阅读