Skip to content

Instantly share code, notes, and snippets.

@TheNorthEestern
Last active June 28, 2017 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheNorthEestern/8fdfe1ec4b27ebe9feb9f07ed2214767 to your computer and use it in GitHub Desktop.
Save TheNorthEestern/8fdfe1ec4b27ebe9feb9f07ed2214767 to your computer and use it in GitHub Desktop.
extension SCNAction {
static func oscillation(amplitude a: CGFloat, timePeriod t: Double) -> SCNAction {
let action = SCNAction.customAction(duration: t) { node, currentTime in
let displacement = a * sin(2 * .pi * currentTime / CGFloat(t))
node.position.x = Float(displacement)
}
return action
}
}
// This code gets excuted inside of a loop on viewDidLoad()
let osc = SCNAction.oscillation(amplitude: (outerLoopVal % 2 == 0 ? 10 : -10), timePeriod: 240)
nodeRow.runAction(SCNAction.repeatForever(osc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment