2017-08-23 45 views
1

我正在尝试做一个模拟小演示,我认为这部分会很容易。男孩是我错了,现在我完全卡住了。这是我的问题。Unity3D旋转表现不如预期

我试图用旋转和针对此问题,我们将用一个30度角的作品,其显示如下的工作:

The green ray is -15 degrees, red is 0 degrees and blue is +15 degrees for a total of 30 degrees.

绿色光线-15度,红色是0度蓝色是+15度,总共30度。

现在我想说划分30度到equalish部分,以便第一的好号码将是10,这意味着我可以得出一个射线每3度,直到我打我的最大的,在这种情况下是+15度。这可以看到下面:

Looks good! There is a small amount of space that is off and if anyone knows why that is please let me know.

看起来不错!有一小部分空间已关闭,如果有人知道这是为什么,请让我知道。

现在,我需要大量的光线,所以我们打算通过10倍上去,提高师100,可以看到下面的数字。另外我需要使用imgur,因为这里只允许有两张图片,所以请耐心等待,谢谢。

https://imgur.com/a/cWDdj

的第一张照片是100块,你可以看到的光线都投左侧。这是一个问题。

第二张照片是与部门增加到1000更糟的是现在的事实得到周围物体一路除了一个15度的区域。

这里是这样做的片段。

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循环,其中所述条件检查,也是旋转功能,其通过“一个块”添加到当前旋转值的第二参数。

对于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)

我完全卡住,不知道为什么它是做什么的它在做。如果您需要解释或澄清的内容,请告诉我!

回答

2

您一个整数,它会返回一个整数除以一个数。你反而需要用浮点数除以返回一个十进制数。

this.transform.rotation.y + (30/100f) 
this.transform.rotation.y + (30/1000f) 

编辑:另外,旋转的组件应该是0,而不是其先前的值,以避免旋转的积累。

transform.Rotate(new Vector3(0, 30/10f, 0)); 
+0

因此,这解决了这个问题的100段,但是1000分仍然没有围绕 – Puddinglord

+0

环缠绕我完全明白你的意思,我补充说,对于这两种情况,但即使是在浮点型的1000段还嘲弄那个戒指光线在物体周围的光线丢失,他们应该显示出来。 – Puddinglord

+0

如果您将较小的数字(如200或500)放入,会发生什么情况? – ryeMoss