1 year ago

#309969

test-img

Damiano Miazzi

Idea how to smooth the animation movement in Scenekit

I'm try to develope a custom gps use Scenekit, so far the app simply move a blue cube on the Scenekit world based on the real GPS position user.

For now i move the cube only on z axis, calculating the difference between latitude.

For simplify the project i sent the CoreLocation position into the GameScene and on the "didRenderScene renderer" I move the cube with the following code.

func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
        let box = self.rootNode.childNode(withName: "box", recursively: true)
        box?.position = SCNVector3(0, 0, zmove)
        
       evaluate(loc: gpsLoc)
    }

func evaluate(loc:CLLocation?){
        
        if countFrame < 30 {
            // skip first few frame....
        } else {
            
            guard let loc = loc else {
                return
            }
            
            if isFirstStart {
                lat1 = loc
                print("Start \(loc.coordinate.latitude)")
                isFirstStart = false
            }
            else {
                if lat1 != loc {
                    print("change")
                    let lat2 = CLLocation(latitude: loc.coordinate.latitude, longitude: 0)
                    
                    let dist = distance(lat1: lat1, lat2: lat2)
                    print("dist \(dist)")
                    zmove = zmove + dist
                    lat1 = loc
                } else {
                    // no update pos
                }
            }
        }
        countFrame = countFrame + 1
        
    }

Here my question:

The cube looks like moving correctly base on the change of the latitude, but.. since the gps location is update only when the delegate did change location fire the change the cube movement is not smooth "jerky".

Looking for some idea how I could smooth the animation while the position is not available.

here what it looks like when it move

loc

swift

sprite-kit

scenekit

core-location

game-development

0 Answers

Your Answer

Accepted video resources