我正在开发的平台游戏中有一辆车辆,我希望能够允许旋转,这样它就可以滚上山等。我想将车辆的正负方向旋转限制在 30 度。
问题是,当我启用旋转并从悬崖上滚下或直边掉落时,我的车辆会从侧面翻转并以头部着地。我一直在寻找一种方法将 zRotation 在每个方向上限制为设定的度数。
我尝试使用本教程中的 IK 约束部分:https://www.raywenderlich.com/129895/sprite-kit-inverse-kinematics-swift-2在我的更新功能中,但没有效果。
然后我发现了这个:https://developer.apple.com/documentation/spritekit/skconstraint/1519706-zrotation#declarations
这似乎正是我所需要的,但我不太清楚如何实现它。任何建议将不胜感激!
最佳答案
这应该可以解决问题:
let thirtyDegrees = CGFloat(0.523599) // Convert degrees to rads.
let rotationRange = SKRange(lowerLimit: -thirtyDegrees, upperLimit: thirtyDegrees)
let rotationConstraint = SKConstraint.zRotation(rotationRange)
let vehicle = SKSpriteNode()
vehicle.constraints = [rotationConstraint]
关于ios - 如何通过 zRotation 约束阻止我的角色过度旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44853745/