bezoadam
bezoadam

Reputation: 587

Check if SCNNodes overlap in view

How to detect if two SCNNodes are overlapping in SCNView? They are added in different x an z axis position but from point of camera they look like they overlap together. I want to detect this and then move one of them up or down. enter image description here

Upvotes: 0

Views: 593

Answers (1)

bezoadam
bezoadam

Reputation: 587

For those who will struggle with this problem later... I fixed this with simdWorldPosition property of SCNNode. Here is the code:

let overlapping = wayNamedLocationNode.infoTextNodes.filter { overlappingTextNode in
                    let x = abs(overlappingTextNode.simdWorldPosition.x - textNode.simdWorldPosition.x)
                    let z = abs(overlappingTextNode.simdWorldPosition.z - textNode.simdWorldPosition.z)
                    if ((x < 4 && x > 0) || (z < 4 && z > 0)) {
                        return true
                    } else {
                        return false
                    }
                }
if overlapping.count > 0 {
     overlapping.forEach { $0.removeFromParentNode() }
}

Firstly I found all overlapping nodes and then I simply remove them from parent node.

Upvotes: 1

Related Questions