2

Ok this one has had me scratching my head for the past couple of hours.

I'm attempting to do raytesting on an SCNScenePhysicsWorld (hitTest in SCNRenderer works without a glitch though)

Steps i take: 1.- properties:

let scene = SCNScene() 
var sceneView = SCNView(frame: CGRectZero, options: [SCNPreferredRenderingAPIKey:NSNumber(unsignedLong: SCNRenderingAPI.OpenGLES2.rawValue)]) 

// hit sphere
let hitSphere = SCNSphere(radius: 55)
var hitNode   : SCNNode! = nil
var hitShape  : SCNPhysicsShape! = nil
var hitBody   : SCNPhysicsBody!  = nil

2.-

setupWorld {
    sceneView.scene = scene
    sceneView.delegate = self    
.
.
.

    hitNode = SCNNode(geometry: hitSphere)
    hitNode.position = SCNVector3Make(0, 0, 0)

    // neither work
    hitShape = SCNPhysicsShape(geometry: hitSphere, options: nil)
    // hitShape = SCNPhysicsShape(node: hitNode, options: nil)
    hitBody  = SCNPhysicsBody(type: .Static, shape: hitShape)
    hitNode.physicsBody = hitBody
.
.
.
    spheresNode.position = SCNVector3Make(0, 0, 0)
    spheresNode.addChildNode(renderNode)
    spheresNode.addChildNode(hitNode)

scene.delegate = self

}

3.-

func renderer(renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: NSTimeInterval) {
.
.
.
let rayHit = scene.physicsWorld.rayTestWithSegmentFromPoint(nearpoint, toPoint: farpoint, options: [SCNPhysicsTestBackfaceCullingKey:false]).first

i keep getting rayHit = nil but i'm 100% sure the hitBody lies within the nearpoint and farpoint

I more than aware i must be missing something here, not sure what though

any clues or pointers?

PS: the nearpoint is inside the hitSphere, the farpoint outside, i want to find the coordinate it hits at. I'm already doing it via SCNSceneRenderer.hitTest but want to learn how to do it by rayTest.

}
David Homes
  • 2,725
  • 8
  • 33
  • 53
  • I'm having the exact same problem. It seemed to work before the Xcode update, now the raytest always returns nil. Maybe it's a compiler problem? – KeyChainDude Nov 09 '15 at 13:10
  • I think i read somewhere in apple forums something linked to TvOS2 or something along those lines. I settled for hitNode.hitTestWithSegmentFromPoint(near, toPoint: far, options: [SCNHitTestBackFaceCullingKey:NSNumber(bool: false), SCNHitTestIgnoreHiddenNodesKey:NSNumber(bool: false)]).first – David Homes Nov 09 '15 at 14:46

0 Answers0