# Web SDK モデル移動後の当たり判定の位置について

**URL:** <https://creatorsforum.live2d.com/t/topic/989>\
**Category:** トラブル報告\
**Created:** [2022 年 7 月 27 日午前 11:38 UTC](https://creatorsforum.live2d.com/t/topic/989 "2022-07-27T11:38:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![momomo](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@momomo](https://creatorsforum.live2d.com/u/momomo)\
**Post date:** [2022 年 7 月 27 日午前 11:38 UTC](https://creatorsforum.live2d.com/t/topic/989/1 "2022-07-27T11:38:04Z")

</div>

【Cubism SDKのバージョン】Cubism SDK for Web R5 beta4  
【スマートフォンの場合などは端末名】macbook pro  
【OS名・バージョン】macOS Monterey 12.4  
【開発使用ツール】Visual Studio 2019  
【不具合の状況】  
translateRelativeを使いモデルの位置を変更しても、当たり判定の位置が変わらない。  
サンプルモデルやR4のサンプルコードで試してみても同じ動作でした。

宜しくお願い致します。

---

<div class="post-metadata">

**Author:** ![ueno\_staff](https://sea1.discourse-cdn.com/flex015/user_avatar/creatorsforum.live2d.com/ueno_staff/32/4_2.png) [@ueno\_staff](https://creatorsforum.live2d.com/u/ueno_staff)\
**Post date:** [2022 年 7 月 28 日午前 10:34 UTC](https://creatorsforum.live2d.com/t/topic/989/2 "2022-07-28T10:34:51Z")

</div>

@momomo 様

お問い合わせいただきありがとうございます。  
Live2Dスタッフです。

モデルの当たり判定処理はモデルが持つMatrixの位置情報を用いて判定しますが、  
translateRelativeをモデルの持つMatrixではなく、画面描画用Matrixに対して使っている可能性があります。

画面描画用Matrixはサンプルコードでは  
lapplive2dmanager.ts ➝ onUpdate() 内で処理されています。

> <https://github.com/Live2D/CubismWebSamples/blob/328f0718d096aec7eefab80774d348ae89c847e0/Samples/TypeScript/Demo/src/lapplive2dmanager.ts#L133>

モデル用Matrixは  
lappmodel.ts ➝ setupLayout() 内の setupFromLayout() で取得した this.\_modelMatrix になります。

> <https://github.com/Live2D/CubismWebSamples/blob/328f0718d096aec7eefab80774d348ae89c847e0/Samples/TypeScript/Demo/src/lappmodel.ts#L330>

\_modelMatrix は CubismModelMatrix クラスです。  
これに対して translateRelative を使うことで、正常な当たり判定を持つ位置変更が可能になります。

参考 :  
・モデルの当たり判定 :  
[https://docs.live2d.com/cubism-sdk-manual/hitarea/](https://docs.live2d.com/cubism-sdk-manual/hitarea/)

・CubismModelMatrix :  
[https://docs.live2d.com/cubism-sdk-manual/layout](https://docs.live2d.com/cubism-sdk-manual/layout/)

ご確認のほど、よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![momomo](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@momomo](https://creatorsforum.live2d.com/u/momomo)\
**Post date:** [2022 年 7 月 29 日午前 5:21 UTC](https://creatorsforum.live2d.com/t/topic/989/3 "2022-07-29T05:21:39Z")

</div>

ご指摘の通り、画面描画のmatrixにtranslateをしていたため、モデルのmatrixに変更したところ、モデルの移動に合わせて当たり判定も移動しました。  
迅速にご返答いただき大変助かりました。ありがとうございます。
