1

I've run this Git. What I'm trying to do is when the node is further than the distance I set, for example 1 meter, node is removed. With in it, I've added this method (Code 1).

Code 1

func getDistanceBtw(cameraPostion: SCNVector3, nodePosition: SCNVector3) -> Float {
    let powX = (cameraPostion.x - nodePosition.x) * (cameraPostion.x - nodePosition.x)
    let powY = (cameraPostion.y - nodePosition.y) * (cameraPostion.y - nodePosition.y)
    let powZ = (cameraPostion.z - nodePosition.z) * (cameraPostion.z - nodePosition.z)
    let powXYZ = powX + powY + powZ
    let distance = sqrt(powXYZ)
    return distance
}

And in renderer didUpdate Node method, I added... (Code 2)

Code 2

let cameraPostion = sceneView.pointOfView?.position
let nodePosition = node.position

if getDistanceBtw(cameraPostion: cameraPostion!, 
                   nodePosition: nodePosition) > 1 {
    node.removeFromParentNode()
}

I thought this my solve what I want to achieve, it did something but not what I wanted.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Jin Heo
  • 43
  • 4
  • Jin, the best way is to use raycasting: https://stackoverflow.com/questions/54842920/arkit-raycasting-using-a-world-ray-instead-of-a-screen-point/62327921#62327921. Raycast object has a `distance` instance property in many cases. – Andy Jazz Oct 15 '20 at 12:04

0 Answers0