I'm trying to add flames to a rocket by using a particle system in Scenekit. The particle file looks fine and I don't get any errors but the particles don't appear when I run the app. Both reactor.scnp and spark.png are in the art.scnassets folder as well as the main app folder.
@objc func sceneTapped(recognizer: UITapGestureRecognizer) {
let location = recognizer.location(in: sceneView)
let hitResults = sceneView.hitTest(location, options: nil)
if hitResults.count > 0 {
let result = hitResults[0] as! SCNHitTestResult
let node = result.node
let physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
rocket.physicsBody = physicsBody
let direction = SCNVector3(0, 3, 0)
let rocketshipNode = rocket
let reactorParticleSystem = SCNParticleSystem(named: "reactor.scnp", inDirectory: nil) //SCNParticleSystem(coder: "art.scnassets/reactor")
print(reactorParticleSystem)
let engineNode = rocket.childNode(withName: "node2", recursively: false)
print(engineNode)
// 3
physicsBody.isAffectedByGravity = false
physicsBody.damping = 0
// 4
let collider = [floor]
reactorParticleSystem?.colliderNodes = collider as? [SCNNode]
// 5
engineNode?.addParticleSystem(reactorParticleSystem!)
// 6
let action = SCNAction.moveBy(x: 0, y: 0.3, z: 0, duration: 3)
action.timingMode = .easeInEaseOut
rocketshipNode!.runAction(action)
}
}
Not sure what the issue was but I recreated the Particle System File and it seems to work fine.