2
我目前有一個用於建築物的物品放置系統。它通過實例化對象的「鬼魂」來顯示它可以放置的位置,鬼魂(半透明)對象被附加到相機並在玩家點擊時在其位置實例化對象。根據Unity中的地形旋轉對象(C#)
我得到它的位置,以保持鬼對象,像這樣:
var pos = transform.position + transform.forward * placeDistance; // A position 'someDistance' in front of the player
pos.y = Terrain.activeTerrain.SampleHeight(pos); // Get the position at the surface of the terrain to place the object
firePlaceable.transform.position = pos + Vector3.up * 0.001f; // 'halfHeight' is used in case the pivot is not on the base
現在..我所需要的對象根據地形旋轉,使得火的地方或多或少正確放置旋轉。有任何想法嗎?最好的計劃是什麼?
非常感謝!這是我做的: 'Ray ray = new Ray(pos + Vector3.up * 10.0f,Vector3.down); \t \t \t RaycastHit hit = new RaycastHit(); \t \t \t如果(Physics.Raycast(射線,出命中)){ \t \t \t \t firePlaceable.transform.rotation = Quaternion.FromToRotation(transform.up,hit.normal)* transform.rotation; \t \t \t}' – 2014-12-02 15:35:45