- Home /
All terrain trees face the same way?
So as you can see in my example all of the trees that I have are facing one direction which id like to be able to change the rotation so that it will seem more natural, any way of doing this instead of having to create seperate prefabs with different rotations for each tree? Thanks!
I'm placing it using the terrain, paint trees method.
Ok. Sorry but i haven't used that tool yet, and unfortunately i don't have time to experiment with it to give you an answer. I hope someone with more knowledge answers this.
Answer by remy_rm · Aug 03, 2018 at 02:32 PM
If your underground is of type terrain you can add your trees to the tree painter and use the mass place trees function with random rotation checked.
Alternatively you can make an editor script that searches for all the trees in your current scene and applies a random rotation to it when you click "rotate" in the newly added "Trees" menu:
[MenuItem("Trees/rotate")]
public static void RotateTrees()
{
foreach (<T> tree in FindObjectsOfType<T>())
{
//for every found tree get the transform fo the gameobject and set its Y rotation to a
//random value beween 0 and 360 degrees (up to 2 decimals)
tree.gameObject.transform.localEulerAngles = new Vector3(0, Random.Range(0f, 360f), 0);
}
}
where in FindObjectsOfType has to be replaced by a component only your tree has (maybe a script called tree or something). Alternatively you can also search by name or tag, whatever floats your boat
Hey cool script, but it does work for gameobjects only. Do you have an idea how to do this with the trees which are placed on the terrain?
In the TerrainData files you have a property TreeInstances.
https://docs.unity3d.com/ScriptReference/TerrainData-treeInstances.html
Your answer
Follow this Question
Related Questions
Rotating a Prefab? 3 Answers
Can terrain trees run their own script? 1 Answer
SpeedTree Trees Extremely High Draw Call Count? 3 Answers
Why is my person walking through trees? 1 Answer
How do you make objects solid? 3 Answers