Hunter Hunter - 8 months ago 42
iOS Question

How to Add a FadeOut Duration to a SCNAction

Hey im trying to figure out how to end scnActions moveto action with a fade out duration. Basically i have a car the car moves to the spot but then suddenly stops Once the action is complete. I was hoping to try and get the car to stop more smoothly. but really i need to figure out how to get a fade out duration on an scnAction anyway. Also I checked on Apple's Developer page but that didn't help. And If the solution is there. I don't know how to put it into usable swift code.

Failed Code With Errors

let moveAction = SCNAction.moveTo(location, duration: 1.5)

moveAction.fadeInWithDuration = 1
moveAction.fadeIn(withDuration: 1)
moveAction = SCNAction.fadeIn(withDuration: 1)
moveAction.fadeOutWithDuration = 1


You'll need to adjust the Timing Mode of your actions to get smooth, slowing movement/changes over time. There are four different modes in Scene Kit (and Sprite Kit).

  1. Linear (the default, what you're seeing)
  2. Ease In (Slow start, Fast finish)
  3. Ease Out (Fast start, Slow finish)
  4. Ease In and Out (Slow finish, fast middle, Slow finish)

This is set via an enum: SCNActionTimingMode that has each of these as a case.

Thanks to the brevity of Swift 3.0, it now looks like this:

let moveAction = SCNAction.move(to: location, duration: 1.5)
    moveAction.timingMode = .easeInEaseOut

There's a much more diverse array of timing action offerings here: