前提・実現したいこと
衝突された方向を、そのオブジェクトの向いてる向きから見て取得したいです。
まだ初心者なもので、調べながらcontactsを使用して実現しようとしましたが、上手くいきませんでした。
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Damage : MonoBehaviour 6{ 7 8 9 void OnCollisionEnter(Collision col) 10 { 11 Debug.Log("hit"); 12 foreach (ContactPoint point in col.contacts) 13 { 14 if (point.point.x - transform.position.x > 0.2) 15 Debug.Log("Left"); 16 17 else if (point.point.x - transform.position.x < -0.2) 18 Debug.Log("Right"); 19 20 if (point.point.y - transform.position.y > 0.5) 21 Debug.Log("Up"); 22 23 if (point.point.z - transform.position.z > 0.2) 24 Debug.Log("Forward"); 25 26 else if (point.point.z - transform.position.z < -0.2) 27 Debug.Log("Back"); 28 29 } 30 } 31}
試したこと
上記のコードでは、ワールド?での方向は取得できましたが、オブジェクトの向きからの方向は取得出来ませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/20 04:57