I am trying to scale and SCNNode in real time using the Pinch gesture:
This is my current code
let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(from:)))
sceneView.addGestureRecognizer(pinchGestureRecognizer)
@objc
func handlePinch(from recognizer: UIPinchGestureRecognizer){
var pinchScale = recognizer.scale
pinchScale = round(pinchScale * 1000) / 1000.0
sceneView.scene.rootNode.enumerateChildNodes { (node, stop) -> Void in
if(node.name == "Box01"){
node.scale = SCNVector3(x: pinchScale, y: pinchScale, z: pinchScale)
}
}
}
However the node doesn't scale big or small? Can someone please point my mistake?
The SCNNode is loaded and has an animation on applied like so,
sceneView.scene.rootNode.addChildNode(node)
loadAnimation(animation: .Attack, sceneName: "art.scnassets/attack", animationIdentifier: "attackID");
childNode(withName:recursively:)
method on your root node instead, that should make this clearer. – jlsiewert