2017-12-25 11 views
0

私は、それらの間に一定の角度を持つ点の周りにベクトル点の「星」を作成しようとしています。元とヒット点の間の元の線です(写真参照)方向との相対的な角度と位置

enter image description here

private void FixedUpdate() 
{ 
    ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
    if (Physics.Raycast(ray, out hit, 3000)) 
    { 

    Vector3 mousePos = hit.point; 
    Debug.DrawLine(transform.position, hit.point, Color.yellow); 

    Vector3[] explorePoints = new Vector3[6] { 
       new Vector3 (hit.point.x - 1 , hit.point.y, hit.point.z + 1), // diag left 
       new Vector3 (hit.point.x + 1 , hit.point.y, hit.point.z + 1), // diag right 
       new Vector3 (hit.point.x - 1 , hit.point.y, hit.point.z), // left 
       new Vector3 (hit.point.x + 1 , hit.point.y, hit.point.z), // right 
       new Vector3 (hit.point.x - 1 , hit.point.y, hit.point.z - 1), // diag left back 
       new Vector3 (hit.point.x + 1 , hit.point.y, hit.point.z - 1), // diag right back 
    }; 

    for (int x = 0; x < explorePoints.Length; x++) 
    { 
     Debug.DrawLine(mousePos, explorePoints[x], Color.red); 
    } 

} 
} 

マウスとの間の角度はもちろんのではない他の角度で、0か180に近づいたときにこれが正常に動作します:

元から小さなオフセットで新しいベクトルを作成することによって行われまし

enter image description here

球とマウスの間の角度を方向ベクトルに適用するには、おそらくQuaternionクラスが必要ですが、実際にはそれを把握することはできません。

Quaternion q = Quaternion.FromToRotation(transform.position, mousePos); 
for (int x = 0; x < explorePoints.Length; x++) 
{ 
     Debug.DrawLine(mousePos, q * explorePoints[x], Color.red); 
} 

は、どのように私はすべての回で黄色の線にN角度で赤のラインを保つのですか?

答えて

1

enter image description here

private void FixedUpdate() 
 
    { 
 
    RaycastHit hit; 
 
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
 
    if (Physics.Raycast(ray, out hit, 3000)) 
 
    { 
 
     Vector3 mousePos = hit.point; 
 
     Debug.DrawLine(transform.position, hit.point, Color.yellow); 
 
     Vector3 rayDir = transform.position - mousePos; 
 
     Vector3[] explorePoints = new Vector3[6] { 
 
     Quaternion.Euler(0, 0, 45) * rayDir.normalized, 
 
     Quaternion.Euler(0, 0, 90) * rayDir.normalized, 
 
     Quaternion.Euler(0, 0, 135) * rayDir.normalized, 
 
     Quaternion.Euler(0, 0, -45) * rayDir.normalized, 
 
     Quaternion.Euler(0, 0, -90) * rayDir.normalized, 
 
     Quaternion.Euler(0, 0, -135) * rayDir.normalized, 
 
     }; 
 

 
     float starLength = 100; 
 
     for (int x = 0; x < explorePoints.Length; x++) 
 
     { 
 
     // we want to use the vector as DIRECTION, not point, hence mousePos + explorePoints[x] (starLength is just the length of the red line) 
 
     Debug.DrawLine(mousePos, mousePos + (explorePoints[x] * starLength), Color.red); 
 
     } 
 
    } 
 
    }

+0

あなたはマウスポイントを移動するおかげで、それはそれはかなりではないですが、角度が一定ではありません。私は方向(transform.position - hit.point)を計算し、その方向に角度をつけたベクトルを作成する必要があると思います。私が動かすことができないビットは、その角度を相対的に一定に保つ方法です世界の空間ではなく、方向。何か案は? – Absinthe

+0

コードを試しましたか? Vector *を60度回転させ、60度回転させないでください。 – AVAVT

+0

はい、それにいくつかの変形があります。時間があれば自分のために試してみて、私は何を意味するのか分かります。 – Absinthe

関連する問題