Swift RealityKit–;如何禁用模型';重力是如何通过编程实现的?

Swift RealityKit–;如何禁用模型';重力是如何通过编程实现的?,swift,augmented-reality,realitykit,Swift,Augmented Reality,Realitykit,我想通过编程在RealityKit中禁用重力,而不需要Reality Composer的任何帮助 let arView = ARView(frame: .zero) let boxAnchor = try! Experience.loadBox() arView.scene.anchors.append(boxAnchor) 如何做到这一点?您可以使用组件[PhysicsBodyComponent]禁用模型的重力: let arView = ARView(frame: .zero) let b

我想通过编程在RealityKit中禁用重力,而不需要Reality Composer的任何帮助

let arView = ARView(frame: .zero)
let boxAnchor = try! Experience.loadBox()
arView.scene.anchors.append(boxAnchor)

如何做到这一点?

您可以使用
组件[PhysicsBodyComponent]
禁用模型的重力:

let arView = ARView(frame: .zero)
let boxAnchor = try! Experience.loadBox()
let entity = boxAnchor.steelBox! as! (Entity & HasPhysics)
    
entity.components[PhysicsBodyComponent] = .none

arView.scene.anchors.append(boxAnchor)
或者使用
physicsBody
实例属性:

entity.physicsBody = .none

您可以使用
组件[PhysicsBodyComponent]
禁用模型的重力:

let arView = ARView(frame: .zero)
let boxAnchor = try! Experience.loadBox()
let entity = boxAnchor.steelBox! as! (Entity & HasPhysics)
    
entity.components[PhysicsBodyComponent] = .none

arView.scene.anchors.append(boxAnchor)
或者使用
physicsBody
实例属性:

entity.physicsBody = .none