使用精灵速度旋转精灵 (swift) flappy bird game

Rotation of sprite by using sprites velocity (swift) flappy bird game

所以我正在学习如何使用 sprite 构建 iOS 游戏。我正在重新制作 flappy bird 作为我的第一个项目。 我不知道如何正确工作的最后一段代码是小鸟在空中落下时的旋转。

当我的鸟通过重力坠落时,它会俯冲下来,这很好。当我在点击屏幕时应用垂直脉冲时。这只鸟直接翻转 180 度,直接垂直看。这有点像我,但我如何平滑从鼻子俯冲到垂直看的过渡?

bird.physicsBody?.allowsRotation = true
var velocityvector = bird.physicsBody?.velocity
let angle = atan2(velocityvector?.dy ?? 0, velocityvector?.dx ?? 0)
bird.zRotation = angle

这是我用来旋转小鸟的代码。

bird.physicsBody?.allowsRotation = true 
var velocityvector = bird.physicsBody?.velocity
let angle = atan2(velocityvector?.dy ?? 0, velocityvector?.dx ?? 0)
let rotateAction = SKAction.rotate(byAngle: angle, duration: 0.5)
// Or let rotateAction = SKAction.rotate(toAngle: angle, duration: 0.5)
bird.run(rotateAction)