我在场景中有2个物理实体。其中一个机体是一个直接向下(由于重力)下降的盒子,另一个是可以在盒子上站立,跑步或跳跃的玩家。
目前,当玩家与掉落的盒子发生碰撞时,它们互相反弹,但是,我不希望他们这样做,我希望盒子和玩家不会相互影响。身体动作,但只是为了让玩家能够站立,跑动和跳跃,而他在盒子上。
这是两个精灵的代码:
func setUpPlayer() {
player.physicsBody = SKPhysicsBody(rectangleOfSize: player.size)
player.physicsBody?.mass = 1
player.physicsBody?.restitution = 0
player.xScale = 0.5
player.yScale = 0.5
player.position = CGPoint(x: 600, y: 800)
addChild(player)
}
func addSquare() {
let squareNode = SKSpriteNode(imageNamed: "fblogo.png")
squareNode.physicsBody = SKPhysicsBody(rectangleOfSize: squareNode.size)
squareNode.physicsBody?.mass = 1
squareNode.physicsBody?.restitution = 0.2
squareNode.physicsBody?.linearDamping = 0
squareNode.physicsBody?.angularDamping = 0
squareNode.physicsBody?.dynamic = true
squareNode.xScale = 0.5
squareNode.yScale = 0.5
squareNode.position = CGPoint(x: 500, y: 700)
self.addChild(squareNode)
squaresArray.addObject(squareNode)
}
答案 0 :(得分:2)
尝试将他们的physicsBody.collisionBitMask设置为零。也许你只能做0:
func setUpPlayer() {
player.physicsBody = SKPhysicsBody(rectangleOfSize: player.size)
player.physicsBody?.mass = 1
player.physicsBody?.restitution = 0
player.xScale = 0.5
player.yScale = 0.5
player.position = CGPoint(x: 600, y: 800)
addChild(player)
}
func addSquare() {
let squareNode = SKSpriteNode(imageNamed: "fblogo.png")
squareNode.physicsBody = SKPhysicsBody(rectangleOfSize: squareNode.size)
squareNode.physicsBody?.mass = 1
squareNode.physicsBody?.restitution = 0.2
squareNode.physicsBody?.linearDamping = 0
squareNode.physicsBody?.angularDamping = 0
squareNode.physicsBody?.dynamic = true
squareNode.physicsBody?.collisionBitMask = 0
squareNode.xScale = 0.5
squareNode.yScale = 0.5
squareNode.position = CGPoint(x: 500, y: 700)
self.addChild(squareNode)
squaresArray.addObject(squareNode)
}
这可能不是 完全 你需要什么,因为我没有在发布之前把它放到Xcode中,以检查它是否有效。但是在对象上设置collisionBitMask意味着它只与传入UInt或变量的BitMask对象“撞到”或“碰撞”。这样,它仍然是动态的,但不受碰撞的物理影响。