2015-04-06 44 views
1

我新來stackoverflow,所以嗨,大家好!要約束唯一的一個矢量軸在統一

而且我也是新來的Unity。我有一個約束我的對象的問題。(對不起,如果我的英文不好) 我想限制我的播放器對象,但只限於一個軸。如果我們不能,我怎麼能解決這個問題,而不是使用框& untick MeshCollider &添加collider 。感謝您的提前:)

+0

你的播放器對象有什麼組件?它如何移動?你需要提供更多關於它的細節,否則我們只能猜測解決方案是什麼。 – SirBraneDamuj

回答

0

是的,你說得對,也許我應該更具體。現在我的代碼正在運行。 舊的和發佈的部分是--->

Hareket是預定義的值,邊界是公共的邊界邊界;

...

GetComponent<Rigidbody>().Velocity=Hareket; LastZ = GetComponent<Rigidbody>().position.z; GetComponent<Rigidbody>().position = new Vector3 ( Mathf.Clamp (GetComponent<Rigidbody>().position.x,boundary.xMin, boundary.xMax), 0.68f, Mathf.Clamp (GetComponent<Rigidbody>().position.z,0f, LastZ) );

....

但我不應該使用的最後一部分Mathf.Clamp (GetComponent<Rigidbody>().position.z,0f, LastZ) 但它應該是唯一的LastZ值。

而且還保持對球的旋轉效果 GetComponent<Rigidbody>().Velocity=Hareket;部分應該是GetComponent<Rigidbody>()AddForce(Hareket); ...

感謝。