Xcoder555 Xcoder555 - 11 months ago 66
iOS Question

How to find the collision location

I am building a game in Spritekit Swift, I have a DidBeginContact detection function between three nodes and the ground, I need to add a variable that lets me use the contact location in the view but I don't know how to do that.
I am hoping that I can use a variable similar to one found in the touchesBegan

let location = touch.locationInNode(self)

any assistance would be appreciated.


Do you want to get the precise location of where the contact happened on the sprite itself? I think thats not possible.

If you just want the general location where the contact happens just get the position property of the node in the contact.

I assume your contact function looks something like this (which it should).

 func didBeginContact(contact: SKPhysicsContact) {

    var firstBody: SKPhysicsBody
    var secondBody: SKPhysicsBody

    if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
        firstBody = contact.bodyA
        secondBody = contact.bodyB
    } else {
        firstBody = contact.bodyB
        secondBody = contact.bodyA

    if (firstBody.categoryBitMask == GROUND CATEGORY) &&  (secondBody.categoryBitMask == OBJECT CATEGORY) {



Just assign the position of the sprite you want to your property you need in the corresponding if statements.

  if (firstBody.categoryBitMask == GROUND CATEGORY) &&  (secondBody.categoryBitMask == OBJECT CATEGORY) {

         if let objectNode = secondBody.node { // safely unwrap 
              yourLocationProperty = objectNode.position

Hope this helps