问题描述
我想让物理世界没有摩擦和阻尼。
我试图将场景的引力设为(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的更新将修复物理引擎的不完善之处。