我正在使用SpriteKit开发2D平台游戏。在我的场景更新方法中,当他向前或向后移动时,我对我的英雄施加冲动
heroPhysicsBody.velocity = CGVectorMake(0,heroPhysicsBody.velocity.dy)
heroPhysicsBody.applyImpulse(CGVectorMake(CGFloat(moveDirection)*680,0))
我在游戏中将两个相同的平台放在一起。
一切正常但是当我的英雄应该从平台A移动到平台B(换句话说:穿过两个平台的边缘)时,他有时会停在那个边缘稍微不同的位置!我总是能够回去,有时它会在回去之后成功地越过边缘。它似乎完全是武断的。
跳过边缘始终有效。
image that shows the platforms and the problematic edge
在调试会话中,我可以确认,当我的英雄被神秘占据时,“移动力”仍然被应用,并且他具有预期的“移动速度”。
我的平台物理机构:
floorGrass.physicsBody = SKPhysicsBody(texture: floorGrassTexture, size: floorGrass.size)
floorGrass.physicsBody!.dynamic = false
floorGrass.physicsBody!.restitution = 0
floorGrass.physicsBody!.friction = 1
floorGrass.physicsBody!.mass = 10
floorGrass.physicsBody!.categoryBitMask = PhysicsCategories.Platform
floorGrass.physicsBody!.contactTestBitMask = PhysicsCategories.None
floorGrass.physicsBody!.collisionBitMask = PhysicsCategories.None
我的英雄物理团体
pbody.affectedByGravity = true
pbody.mass = 5
pbody.linearDamping = 1
pbody.friction = 1
pbody.restitution = 0
pbody.velocity = CGVector(dx: 0,dy: 0)
pbody.categoryBitMask = PhysicsCategories.Character
pbody.contactTestBitMask = PhysicsCategories.Platform | PhysicsCategories.Flame | PhysicsCategories.Stachelfalle | PhysicsCategories.Bamboostick
pbody.collisionBitMask = PhysicsCategories.Platform | PhysicsCategories.Stachelfalle | PhysicsCategories.Blocker
由于