我正在尝试围绕一个点创建一个矢量点的“星形”,它们之间的角度恒定,源和命中点之间的原始线(见图)我通过创建具有小偏移量的新矢量来完成从原文:
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 时,这可以正常工作,但在其他角度当然不行:
我知道我可能需要 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角?