我開始使用Unity進行開發。 我在做這樣的事情:Unity3D C#計算旋轉後的正確轉發
if(Input.GetKey(KeyCode.A))newValues[1]-=this.turnSpeed*(float)Time.deltaTime;
if(Input.GetKey(KeyCode.D))newValues[1]+=this.turnSpeed*(float)Time.deltaTime;
transform.Rotate(0, newValues[1], 0);
if(Input.GetKey(KeyCode.W))newValues[0]+=this.speed*transform.forward.z*(float)Time.deltaTime;
if(Input.GetKey(KeyCode.S))newValues[0]-=this.speed*transform.forward.z*(float)Time.deltaTime;
transform.position = new Vector3(transform.position.x, transform.position.y, (float)newValues[0]);
所以我旋轉,我可以移動,但移動只是在Z行,我知道我呼籲在Z特定的運動。 但使用JavaScript,我可以做一些事情
transform.forward+=this.speed*transform.forward*(float)Time.deltaTime;
所以我並不需要做新的向量處理,並複製到一個獨立的變量,它的工作原理就像一個魅力,利用旋轉和利用爲導向,以自己的時候它被旋轉了。
你或許應該修改標題和標籤。所使用的統一標籤是指MS應用程序塊中的依賴注入容器。你可能指的是unity-3D,如果這是爲了遊戲,你可能需要添加一個合適的標籤。 – Tod 2012-03-10 01:09:50
如果在C#代碼中放置'transform.forward + = this.speed * transform.forward *(float)Time.deltaTime',會發生什麼? Javascript和C#都編譯爲相同的.NET中間語言,因此如果代碼稍有不同,幾乎任何可能的東西都可能在另一箇中。 – 2012-03-10 01:32:29
它不工作,它是一個只讀變量 – Lefsler 2012-03-10 02:37:44