-
-
Save AbhinavChauhan97/a40b5e5f15a2498de5a7cee823b83602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun flyPlane() { | |
var distance = 0f | |
val tan = floatArrayOf(0f,0f) | |
val pos = floatArrayOf(0f, 0f) | |
val valueAnimator = ValueAnimator.ofFloat(0f, 1f) | |
valueAnimator.duration = (pathMeasure.length * 5).toLong() | |
valueAnimator.interpolator = AccelerateDecelerateInterpolator() | |
valueAnimator.addUpdateListener { | |
distance = it.animatedValue as Float | |
pathMeasure.getPosTan(distance * pathMeasure.length, pos, tan) | |
val planeX = pos[0] | |
val planeY = pos[1] | |
plane.x = planeX | |
plane.y = planeY | |
val degrees = atan2(tan[1], tan[0]) * 180.0 / Math.PI | |
plane.rotation = degrees.toFloat() - 180 | |
} | |
valueAnimator.doOnEnd { | |
if (pathMeasure.nextContour()) { | |
flyPlane() | |
} | |
} | |
valueAnimator.start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment