【发布时间】:2017-08-23 15:40:22
【问题描述】:
我正在尝试为模拟制作一个小型演示,我认为这部分会很容易。男孩是我错了,现在我完全被困住了。这是我的问题。
我正在尝试使用旋转,对于这个问题,我们将使用 30 度角,如下所示:
绿光是-15度,红光是0度,蓝光是+15度,总共30度。
现在我想将所说的 30 度分成相等的部分,所以第一个好的数字是 10。这意味着我可以每 3 度绘制一条射线,直到达到最大值,在这种情况下为 +15 度。这可以在下面看到:
看起来不错!有少量空间关闭,如果有人知道这是为什么,请告诉我。
现在,我需要大量光线,因此我们将增加 10 倍并将分割数增加到 100,如下所示。另外我需要使用imgur,因为这里只允许使用两张图片,所以请多多包涵,谢谢。
第一张图片有 100 个块,你可以看到光线都投射到左边。这是个问题。
第二张图片是分割数增加到 1000。现在更糟糕的是,除了 15 度的区域外,它一直围绕着对象。
这是执行此操作的 sn-p。
if(testRotation)
{
//Sets the objects rotation to the starting rotation which is -15 degeres
this.transform.Rotate(this.transform.rotation.x, this.transform.rotation.y - 15.0f,
this.transform.rotation.z);
for (int i = 0; i <= 10; i++)
{
//Draws a ray at the current position and forwards relative to the objects transform
Debug.DrawRay(this.transform.position,
this.transform.forward * maxSightDistance, Color.cyan, 1000.0f);
//This advances the rotation by a factor of one chunk
//which in this case is 10 which seems to work
this.transform.Rotate(new Vector3(this.transform.rotation.x,
this.transform.rotation.y + (30/10), this.transform.rotation.z));
}
//This makes it so it doesn't run forever
testRotation = false;
}
唯一改变的地方是在检查条件的 for 循环中,以及 Rotate 函数的第二个参数,它通过“一个块”添加到当前旋转值。
对于 100 个块,我将其修改为:for(int i = 0; i < 100; i++) 和 this.transform.rotation.y + (30/100)
对于 1000 个块,我将其修改为:for(int i = 0; i < 1000; i++) 和 this.transform.rotation.y + (30/1000)
我完全被卡住了,不知道为什么它正在做它正在做的事情。另外,如果您需要解释或澄清某些事情,请告诉我!
【问题讨论】: