1

ここで助けが必要です。raycastでブロックされていないネイバーを検索するコードの一部があります。「WP」タグと衝突するレイキャストを取得する必要があります。どちらの反復も正しい結果を示したので、ダンプとレイキャストを実行すると、レイキャストは何かを衝突させることに成功しますが、レイキャストが衝突したものを確認すると、結果は表示されません....これの何が問題なのか誰もが知っていますコード..??

int flag = 0, flahNeigh = 0;
    for(flag = 0; flag< wayPoints.WPList.Length; flag++) // iteration to seek neighbour nodes
            { 
                for (flagNeigh = 0; flagNeigh < wayPoints.WPList.Length; flagNeigh++)
                {                
                    if (wayPoints.WPList[flag].loc != wayPoints.WPList[flagNeigh].loc) // dump its own node location
                    {                    
                        if (Physics.Raycast(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position, out hitted)) // raycasting to each node else its self
                        {  
                            if (hitted.collider.gameObject.CompareTag("WP")) // check if the ray only collide the node
                            {
                               print(flag + "  :  " + flagNeigh + "  :  " + wayPoints.WPList[flagNeigh].loc.position); // debugging to see whether the code works or not (the error comes)
                            }
                        }
                    }                    
                }
            }

感謝と答えをありがとう...私が悪い英語を持っているならごめんなさい...^^

4

1 に答える 1

0

隣人の位置を使っているからです。これは、原点が0,0,0からの場合にのみ機能します。

だから書く代わりに:

if (Physics.Raycast(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position, out hitted))

書く :

 if (Physics.Raycast(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position-wayPoints.WPList[flag].loc.position, out hitted)) 
于 2012-12-30T03:27:59.740 に答える