我有一个球和一个平面(地板)在realityKit
.
在飞机上,球落到了collide
度.但球是falling
-through
的飞机.当球击中平面时,我想要一条打印声明"发生",但这也没有发生.
我的代码是:
struct ARViewContainer: UIViewRepresentable {
let arView = ARView(frame: .zero)
func makeUIView(context: Context) -> ARView {
var subscriptions: [Cancellable] = []
let anchor = AnchorEntity()
//generate a plane
let planeModel = ModelEntity(mesh: .generatePlane(width: 2.0,
depth: 2.0))
as (Entity & HasCollision)
planeModel.position = [0,-10,-1.5]
planeModel.generateCollisionShapes(recursive: true)
//generate a ball
let ballModel = ModelEntity(mesh: .generateSphere(radius: 0.4))
as (Entity & HasCollision & HasPhysicsBody)
ballModel.generateCollisionShapes(recursive: true)
ballModel.position = [0,0, -1.5]
ballModel.physicsBody = .init()
ballModel.physicsBody?.mode = .dynamic
let sub = arView.scene.subscribe(to: CollisionEvents.Began.self,
on: ballModel) { _ in print("OCCURED!") }
subscriptions.append(sub)
anchor.addChild(ballModel)
anchor.addChild(planeModel)
arView.scene.addAnchor(anchor)
return arView
}
}