0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[ARKit] 衝突判定を実現するメモ

Posted at

衝突判定する流れ

ARViewにコリジョンの有効、無効を設定する

// physicsにすると現実世界の物体と衝突した際もぶつかる。
   arView.environment.sceneUnderstanding.options = [.collision]

ARSessionを開始する
ARObjectを配置する
モデルエンティティにコリジョンコンポーネントをアタッチする

 model.generateCollisionShapes(recursive: false)

エンティティの衝突を検出してイベントを発行する
コリジョンイベントを受診して処理を行う。

コリジョンイベントを検知するためにcombineを使ってシーンをサブスクライブする

 collisionBegan = arView.scene.subscribe(to: CollisionEvents.Began.self,
                                                実現したいメソッド)

コリジョンイベント3種類

CollisionEvents.Began
衝突が起きたタイミングで発生する
CollisionEvents.Updated
衝突が起きてから衝突が継続されている間発生する
CollisionEvents.Ended
衝突がなくなった直後に発生する
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?