###前提・実現したいこと
Unity C# Overlapbox(衝突判定)について質問です。
あるゲームオブジェクトの前方にOverlapboxの判定を行いたいのですが
判定の発生位置が意図したものと違い、可視化もできないもので困っています。
Colliderをアタッチしての判定も考えたのですができれば複数オブジェクトの判定を取れる
Overlapboxを使用したいです。
###発生している問題・エラーメッセージ
実際に、衝突のテストを行った所、衝突判定はできているものの、gameobjectの前方に出ているとは 思えない挙動が確認できました。引数はoverlapboxの位置、大きさ、回転角度、と言う認識なのですがなにか見当違いでしょうか? 上手く意図した(gameobjectに向かって前方に当たり判定を行う)挙動になってくれません。 SubAttackは、MonoBehaviourを継承していないので、可視化等も上手くできず困っております。
###該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine.Networking; 4using UnityEngine; 5 6[CreateAssetMenu(menuName = "Skill/MU/SubAttack")] 7public class MUSAttack : SubAttack 8{ 9 public int takeEffecr; 10 public int getEffect; 11 public int damage; 12 public ParticleDataBase PD; 13 14 public override ActionInform subattack(GameObject gameobject){ 15 16 Collider[] colliders = 17 Physics.OverlapBox(gameobject.transform.position + new Vector3(0, 0.8f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f) ,gameobject.transform.rotation); 18 List<GameObject> targets = new List<GameObject>(); 19 for (int i = 0; i < colliders.Length;i++){ 20 if(colliders[i].transform.root != gameobject.transform && colliders[i].tag =="Player") 21 { 22 targets.Add(colliders[i].gameObject); 23 } 24 } 25 if(targets != null && targets.Count > 2) 26 { 27 Vector3[] posns = new Vector3[targets.Count]; 28 GameObject[] targetArray = new GameObject[targets.Count]; 29 for (int i = 0; i < targets.Count;i++) 30 { 31 targetArray[i] = targets[i]; 32 posns[i] = targets[i].transform.position; 33 } 34 Debug.Log(targetArray); 35 return new ActionInform();//new ActionInform(targets, posns, getEffect, damage); 36 } 37 else if(targets.Count > 0) 38 { 39 Debug.Log(targets[0]); 40 return new ActionInform(targets[0], targets[0].transform.position, getEffect, damage); 41 } 42 else 43 { 44 return new ActionInform(); 45 } 46 47 } 48 public void mUSAttack() { } 49 50}
###試したこと
値を調整しましたが、上手く行きませんでした。判定はgameobjectの周辺には出ているものの
前方に出ているかについて疑問符がつきました。overlapsphereでも検討しましたが
こちらの場合角度が設定できないのでgameobjectの向いている方向と合わせられませんでした、
回転角度(orientation)の認識が何か間違っているのでは?
と考えておりますが、数値調整をする上で、なにか最適な方法はあるのでしょうか?
###補足情報(言語/FW/ツール等のバージョンなど)
C#,Unity2017.1.0f3Personal

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/12 06:01