Swift – How do I detect the exact point at which two "SKPhysicsBody(edgeFromPoint:" type physics bodies intersect in sprite kit

| | August 4, 2015

I have two physics bodies attached to two separate sprite nodes using Sprit Kit. One is a vertical line and one is a horizontal line:

//sprite with horizontal physics body
spriteMatrix[i][j].physicsBody = SKPhysicsBody(edgeFromPoint: CGPointMake(0, tileSegmentHeight), toPoint: CGPointMake(tileSegmentWidth, tileSegmentHeight))
spriteMatrix[i][j].physicsBody!.categoryBitMask = self.surfaceCatagory
spriteMatrix[i][j].physicsBody!.contactTestBitMask = heroCatagory

//sprite with vertical physics body
self.hero.physicsBody = SKPhysicsBody(edgeFromPoint: CGPointMake(self.hero.frame.width / 2, self.hero.frame.height / 2), toPoint: CGPointMake(self.hero.frame.width / 2, -20))
self.hero.physicsBody!.categoryBitMask = heroCatagory
self.hero.physicsBody!.contactTestBitMask = surfaceCatagory

What I’m want to do is test if they are intersecting on every frame, and if they are, return the x and y position of where they are intersecting. Is this even possible?

One Response to “Swift – How do I detect the exact point at which two "SKPhysicsBody(edgeFromPoint:" type physics bodies intersect in sprite kit”

  1. This is not possible. Apparently, only a dynamic volume physics body can make contact with an edge body. I do not like this about Sprite Kit.

Leave a Reply