####physics body物理形體
####physics shapes物理形狀
###獲取相機中心
ARFrame * frame = self.jpARSCNView.session.currentFrame;
SCNMatrix4 mat = SCNMatrix4FromMat4(frame.camera.transform);
SCNVector3 dir = SCNVector3Make(-1* mat.m31, -1* mat.m32 , -1* mat.m33);
SCNVector3 pos = SCNVector3Make(mat.m41,mat.m42 ,mat.m43);
bulletsNode.position = pos;
SCNVector3 bulletDirection = dir;
[bulletsNode.physicsBody applyForce:bulletDirection impulse:YES];
[self.jpARSCNView.scene.rootNode addChildNode:bulletsNode];
複製程式碼
###檢測碰撞事件 ######和以往iOS的代理事件不同 它還要多設定categoryBitMask、contactTestBitMask屬性的id 用於標誌2個物體是否會發生碰撞
#####代理設定
_jpARSCNView.scene.physicsWorld.contactDelegate = self;
self.physicsBody.categoryBitMask = 2; self.physicsBody.contactTestBitMask = 1;
// 這裡是自己獨立開一條執行緒出來 — (void)physicsWorld:(SCNPhysicsWorld *)world didBeginContact:(SCNPhysicsContact *)contact ;