2017-08-23 43 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