I am working on PhysicsBody and get some troubles. First I don't really now if this is with PhysicsBody possible or only with pixel check.
The problem is: Contact check works pretty well but if a node is inside a PhysicsBody it won't be able to see if it collides. in the Pictures it is pretty well explained.
Some ideas how it works? Maybe PhysicsBody(Green Line) fill with the SKNode?
Here some Code: (Some explain: if Human moves inside Object and Touched is false nothing happened and it is okay but if Human is moved inside Object and Touched will be True nothing happened too and this is my problem.)
enum myContacts: UInt32 {
case None = 0
case All = 0xFFFFFFFF
case Object = 0b001
case Human = 0b010
}
class whatever...{
let Object = SKSpriteNode(imageNamed: "xyz")
Object.position = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame))
Object.physicsBody = SKPhysicsBody(circleOfRadius: Object.size.width/2)
Object.physicsBody?.dynamic = true
Object.physicsBody?.categoryBitMask = myContacts. Object.rawValue
Object.physicsBody?.contactTestBitMask = myContacts.Human.rawValue
Object.physicsBody?.collisionBitMask = 0
Object.physicsBody?.usesPreciseCollisionDetection = true
addChild(Object)
let Human = SKSpriteNode(imageNamed: "zyx")
Human.position = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame))
Human.physicsBody = SKPhysicsBody(circleOfRadius: Human.size.width/2)
Human.physicsBody?.dynamic = true
Human.physicsBody?.categoryBitMask = myContacts. Human.rawValue
Human.physicsBody?.contactTestBitMask = myContacts.Object.rawValue
Human.physicsBody?.collisionBitMask = 0
Human.physicsBody?.usesPreciseCollisionDetection = true
addChild(Human)
}
func didBeginContact(contact: SKPhysicsContact) {
if touched {
let contactMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
switch contactMask {
case myContacts.Object.rawValue | myContacts.Human.rawValue:
print("Human touched")
default:
break
}
}
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
touched = true
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
touched = false
}