如何在SpriteKit中跳转后使播放器节点站立?

时间:2019-10-30 19:18:10

标签: ios swift sprite-kit

我根据纹理为玩家(兽人)创建了一个物理物体。

player.physicsBody = SKPhysicsBody(texture: player.texture!, size: player.texture!.size())
player.physicsBody?.isDynamic = true
player.physicsBody?.usesPreciseCollisionDetection = true
player.physicsBody?.categoryBitMask = CollisionCategoryBitmask.Player
player.physicsBody?.collisionBitMask = 1
player.physicsBody?.restitution = 0
player.physicsBody?.friction = 1
ground?.physicsBody?.restitution = 0

enter image description here

并且通过施加冲动来创建跳跃动作

 func jumpPlayer(){
    player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 60))
 }

跳跃后,一旦降落,玩家节点似乎失去平衡并掉落。

enter image description here

如何避免这种情况?

1 个答案:

答案 0 :(得分:0)

可以通过将allowRotation设置为false来解决此问题

player.physicsBody?.allowsRotation = false