                 dampedFrequency = naturalFrequency * sqrt(1 - pow(dampingRatio, 2))
                 t1 = 1 / (naturalFrequency * (dampingRatio - sqrt(pow(dampingRatio, 2) - 1)))
                 t2 = 1 / (naturalFrequency * (dampingRatio + sqrt(pow(dampingRatio, 2) - 1)))
+                
+                if dampingRatio < 1 {
+                    A = initialDistance
+                    B = (dampingRatio * naturalFrequency - velocity) * initialDistance / dampedFrequency
+                }  else if dampingRatio == 1 {
+                    A = initialDistance
+                    B = (naturalFrequency - velocity) * initialDistance
+                } else {
+                    A = (t1 * t2 / (t1 - t2)) * initialDistance * (1/t2 - velocity)
+                    B = (t1 * t2 / (t2 - t1)) * initialDistance * (1/t1 - velocity)
+                }
             }
 
             var currentValue: CGFloat!

            if elapsedTime < CGFloat(duration) {

                if dampingRatio < 1 {

                    A = A ?? initialDistance
                    B = B ?? (dampingRatio * naturalFrequency - velocity) * initialDistance / dampedFrequency

                    currentValue = finalValue - exp(-dampingRatio * naturalFrequency * elapsedTime) * (A * cos(dampedFrequency * elapsedTime) + B * sin(dampedFrequency * elapsedTime))
                }
                else if dampingRatio == 1 {

                    A = A ?? initialDistance
                    B = B ?? (naturalFrequency - velocity) * initialDistance

                    currentValue = finalValue - exp(-dampingRatio * naturalFrequency * elapsedTime) * (A + B * elapsedTime)
                }
                else {

                    A = A ?? (t1 * t2 / (t1 - t2)) * initialDistance * (1/t2 - velocity)
                    B = B ?? (t1 * t2 / (t2 - t1)) * initialDistance * (1/t1 - velocity)

                    currentValue = finalValue - A * exp(-elapsedTime/t1) - B * exp(-elapsedTime/t2)
                }
            }
            else {

    private class func animateKeyPath(keyPath: String, byValue: CGFloat!, toValue: CGFloat!, duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat) -> SKAction {
        
        var initialValue: CGFloat!
        var naturalFrequency: CGFloat = 0
        var dampedFrequency: CGFloat = 0
        var t1: CGFloat = 0
        var t2: CGFloat = 0
        var A: CGFloat = 0
        var B: CGFloat = 0
        var finalValue = toValue
        var initialDistance = byValue
        
