道路を作るスクリプトを作成しています。
ですが、道路の幅が一定になりません。ベクトルの扱い方に問題があるのではないかと疑っています。
解決方法を教えてくださると嬉しいです。
<今回作成したスクリプトの頂点指定の流れ>
2本線を表示したいので、RoadMakerと言うオブジェクトにrightとleftと言う子オブジェクトを持たせました。
RoadMakerでは道路の中心点を指定します。
rightとleftは中心点を取得し、1つ前の中心点、1つ後の中心点の差のベクトルを求めます。(section[i].direction)
差のベクトルを90度回転し、単位ベクトル化した後、
道路の長さをかけ(rightは正、leftは負)、道路の左右それぞれの頂点を決める…と言う流れです。
C#
1void SetVectors(){ 2 if (points == null || points.Length < 2)return;//if there not more points than 2, quit this logic. 3 sections = new section[points.Length]; 4 for(int i = 0; i < points.Length; i++){ 5 if (i == 0) { 6 sections [i].direction = points [i+1] - points [i];//StartPoint 7 } else if (i == points.Length - 1) { 8 sections [i].direction = points [i] - points [i - 1]; 9 } else { 10 sections [i].direction = points [i + 1] - points [i - 1]; 11 } 12 13 sections [i].direction.Normalize(); 14 sections [i].direction = Quaternion.AngleAxis(90f,Vector3.up) * sections [i].direction; 15 sections [i].direction.Normalize(); 16 17 sections [i].right = points [i] + (RoadLength+LineLength / 2 )* sections [i].direction; 18 sections [i].left = points [i] + (RoadLength- LineLength / 2 ) * sections [i].direction; 19 } 20 }
写真は、始点から(10,0,0),(10,0,10),(0,0,10)とした時の実行結果です。
始点と第2中心点で、明らかに幅が異なっています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/30 10:51 編集