在RealityKit中,我如何才能使世界无摩擦?

问题描述

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

我试图将场景的引力设为(0,0),并制作一个正方形和一个球,在敲击时施加力。我想让球永远移动,但是它会在一段时间后停止。

如何使实体摩擦为零?

enter image description here

解决方法

将新的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的更新将修复物理引擎的不完善之处。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...