Awesome Open Source
Awesome Open Source


Animate a SCNNode along a curved path in SceneKit.

Linter Status Build Status

License Platform SwiftPM Swift 5.0


Swift Package Manager

Add the URL of this repository to Xcode 11 with minimum version 1.3.0


Add the following to your Podfile pod 'SCNBezier'



Using this framework you can animate a Node along a bézier path using the following example code:

let myNode = SCNNode(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0))
let bezPositions = [
  SCNVector3(-1, 1, 0.01),
  SCNVector3(1, 0.5, 0.4),
  SCNVector3(1.0, -1, 0.1),
  SCNVector3(0.4, -0.5, 0.01)
myNode.runAction(SCNAction.moveAlong(points: bezPositions, duration: 3, fps: 12))

The animation will use duration * fps points to animated between; this requires type Double, or its TypeAlias TimeInterval. This does not mean it will not be smooth, it just means it will make the curve out of that many points, so in this example it will use 36 points along the Bézier curve.

Getting a Bézier curve

The class SCNBezierPath can be created if you want to collect n points along a path for positioning objects etc. as such:

let path = SCNBezierPath(points: points)
for point in path.getNPoints(count: 20) {
	let newNode = SCNNode(geometry: nodeGeometry)
	newNode.position = point

Position on a Bézier curve

If you want to get a point some percentage along the curve, there's a function that makes that easy for you too.

let path = SCNBezierPath(points: points)
let quaterWay = path.posAt(time: 0.25) // gets the point 25% along from start to end

With points, nodeGeometry and parent being arbitrary values.

Bézier example

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
swift (7,620
cocoapods (563
swift-package-manager (123
arkit (90
scenekit (48
bezier (33
cocoapod (30
swiftpm (23

Find Open Source By Browsing 7,000 Topics Across 59 Categories