首页 > 解决方案 > ARKit 物理对象逐步通过跟踪平面

问题描述

我目前正在尝试修改苹果提供的平面跟踪演示,以使小立方体弹丸从应用程序创建的跟踪平面反弹。

我已将物理实体添加到各自的射弹和墙壁,但由于某种原因,射弹继续忽略碰撞并只是穿过墙壁的阶段。我尝试添加和删除位掩码,但它们似乎没有任何影响。

这是我目前正在为我的履带飞机做的事情:

init (anchor: ARPlaneAnchor, in sceneView: ARSCNView) {
        guard let meshGeometry = ARSCNPlaneGeometry(device: sceneView.device!) else {
            fatalError("CANNOT CREATE GEOMETRY")
        }

        meshGeometry.update(from: anchor.geometry)
        meshNode = SCNNode(geometry: meshGeometry)
        meshNode.name = "ENV."        
        super.init()

        self.setupMeshVisualStyle()
        let body = SCNPhysicsBody(type: .static, shape: nil)
        meshNode.physicsBody = body
        addChildNode(meshNode)
    }

这是子弹物理实现

class func spawnBullet() -> SCNNode {
        // Omitted code (just setting size and stuff)

        let cubeNode = SCNNode(geometry: cubeGeometry)
        cubeNode.name = "BULLET"
        let physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic, shape: nil)
        physicsBody.isAffectedByGravity = false
        physicsBody.damping = 0
        physicsBody.categoryBitMask = CollisionCategory.bullet.rawValue
        physicsBody.collisionBitMask = CollisionCategory.env.rawValue | CollisionCategory.player.rawValue
        physicsBody.continuousCollisionDetectionThreshold = 0.01;
        cubeNode.physicsBody = physicsBody
        return cubeNode
    }

我创建了一个单独的 SCNPlane 对象,其物理体设置与跟踪平面设置完全相同。奇怪的是,子弹成功地从 SCNPlane 上相撞,但它们继续以完全相同的设置穿过被跟踪的飞机。

标签: physicscollisionarkitbitmask

解决方案


推荐阅读