Pavan K Pavan K - 10 months ago 55
iOS Question

scaling a SCNNode in runtime using the pan gesture

I am trying to scale and SCNNode in real time using the pan gesture:

This is my current code

let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(from:)))

func handlePinch(from recognizer: UIPinchGestureRecognizer){
var pinchScale = recognizer.scale
pinchScale = round(pinchScale * 1000) / 1000.0

sceneView.scene.rootNode.enumerateChildNodes { (node, stop) -> Void in
if( == "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,

loadAnimation(animation: .Attack, sceneName: "art.scnassets/attack", animationIdentifier: "attackID");

Answer Source

I used this to handle the scale:

func handlePinch(from recognizer: UIPinchGestureRecognizer){
    var pinchScale = round(recognizer.scale * 1000)/1000000
    let node_arm = sceneView.scene.rootNode.childNode(withName: "army", recursively: true)
    node_arm?.runAction(.customAction(duration: 0, action: { node, progress in
        node.physicsBody = nil
        node.scale = SCNVector3(x: Float(pinchScale), y: Float(pinchScale), z: Float(pinchScale))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download