0

如何防止两个精灵节点在碰撞时倾斜。假设我有一个带有 PhysicsBody 1 的长矩形和一个带有 PhysicsBody 2 的短矩形。我希望这两个能够击中,但不希望长矩形在碰撞后倾斜但仍然笔直站立。我怎样才能做到这一点?这是长矩形的代码:

thePlayer.position = CGPoint(x: 100 - self.frame.size.width/2, y: 100 - self.frame.size.height/2)
thePlayer.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 40, height: 40))
thePlayer.physicsBody?.categoryBitMask = gamePhysics.Player
thePlayer.physicsBody?.collisionBitMask = gamePhysics.Wall
thePlayer.physicsBody?.contactTestBitMask = gamePhysics.Wall
thePlayer.physicsBody?.isDynamic = true
thePlayer.physicsBody?.affectedByGravity = false

这是短矩形的代码:

tileNode.position = CGPoint(x: x, y: y)
tileNode.physicsBody = SKPhysicsBody.init(rectangleOf: tileSize, center: CGPoint(x: tileSize.width / 2.0, y: tileSize.height / 2.0))
tileNode.physicsBody?.categoryBitMask = gamePhysics.Wall
tileNode.physicsBody?.collisionBitMask = gamePhysics.Player
tileNode.physicsBody?.contactTestBitMask = gamePhysics.Player
tileNode.physicsBody?.isDynamic = false
4

1 回答 1

0

正如 New Dev 提到的,解决方案很简单。我添加了 node.physicsBody?.allowsRotation = false 并且它有效。

于 2020-05-26T03:29:47.967 回答