Unity3d猎枪锥射击

问题描述:

我正在使用raycast作为霰弹枪。我随机方向每条射线:Unity3d猎枪锥射击

Vector3 direction = new Vector3 (UnityEngine.Random.Range (-splash, splash), UnityEngine.Random.Range (-splash, splash), 100); 

一切工作正常,但这个方向的那个最大的“范围”是矩形,我想一个椭圆。这很难解释: Raycast 这似乎我应该使用规范化的地方,但我不知道在哪里。

+3

http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly –

圆上点的坐标可以像这样计算x = r*cos(a), y = r*sin(a)。如果r是随机的,点将在半径为“飞溅”的圆内;

Vector3 direction = new Vector3(Random.Range(-splash,splash)*Mathf.Cos(Random.Range(0,2*Mathf.PI)),Random.Range(-splash,splash)*Mathf.Sin(Random.Range(0,2*Mathf.PI)),0); 
+0

谢谢,我忘了数学:) – Konowy

+1

团结有一个名为随机函数.insideUnitSphere还有Random.insideUnitCircle。不知道这是否有助于你的情况... http://docs.unity3d.com/ScriptReference/Random.html –