Is it possible and how can i roate the terrain?
6 Answers
6I was just looking for this myself. After playing with it a bit I was able accomplish this with the help of Photoshop:
- Select Terrain
- On the main menu choose Terrain->Export Heightmap - RAW
Settings:
- Depth:16bit
- Byte Order: I chose Win for since I’m on windows… Don’t know how this works out on Mac.
Keep note of the texture size. You will need this in photoshop.
-
Open Photoshop if you haven’t already.
-
Choose Open and browse to your file.
Settings should be:
- Width:[Same as you noted before]
- Height:[Same as you noted before]
- Channels:1
- Depth:16bits
- Byte Order:Whatever you selected (I chose Win)
- Header Size: 0 bytes
Hopefully at this point you are looking at a greyscale image. Now rotate, mirror, or modify as you please. When done, save as a .RAW and choose 16bit for depth.
Keep in mind that Unity will be looking for a square heightmap. If you rotate anything other than increments of 90deg, you will need to fill in that empty space with something…
Back in Unity, with your terrain selected choose Terrain->Import Heightmap - RAW. If all goes well your terrain should be rotated.
Hope this helps!
I know this is a very old question but the answer is, SURE you can rotate your terrain ![]()
Here is an Editor script that rotates your terrain 90 degrees clockwise. It handles the terrain itself (heightmap), the splat map, detail map AND trees. The only thing it does not handle are your GameObjects that you’ve added to it. It wouldn’t be that hard to implement transforming the game objects too though. The other thing is, this script requires your terrain be square. I’ve never even tried to generate a non-square terrain… Can you even do that ??
So, by clicking “Rotate 90 Deg” in your menu multiple times, you can achieve 4 different transformations of your terrain. Pressing it 4 times will return it to the original orientation. It’ll take 10-20 seconds per rotation.
[MenuItem ("Game Tools/Rotate 90 Deg")]
static void rotate() {
int i,j;
var ter = Terrain.activeTerrain;
var td=ter.terrainData;
//rotate heightmap
var hgts=td.GetHeights(0,0,td.heightmapWidth,td.heightmapHeight);
var newhgts=new float[hgts.GetLength(0),hgts.GetLength(1)];
for(j=0;j<td.heightmapHeight;j++) {
for(i=0;i<td.heightmapWidth;i++) {
newhgts[td.heightmapHeight-1-j,i]=hgts[i,j];
}
}
td.SetHeights(0,0,newhgts);
ter.Flush();
//rotate splatmap
var alpha=td.GetAlphamaps(0,0,td.alphamapWidth,td.alphamapHeight);
var newalpha=new float[alpha.GetLength(0),alpha.GetLength(1),alpha.GetLength(2)];
for(j=0;j<td.alphamapHeight;j++) {
for(i=0;i<td.alphamapWidth;i++) {
for(int k=0;k<td.splatPrototypes.Length;k++) {
newalpha[td.alphamapHeight-1-j,i,k] = alpha[i,j,k];
}
}
}
td.SetAlphamaps(0,0,newalpha);
//rotate trees
var size=td.size;
var trees=td.treeInstances;
for(i=0;i<trees.Length;i++) {
trees<em>.position=new Vector3(1-trees_.position.z,0,trees*.position.x);*_</em>
trees.position.y = td.GetInterpolatedHeight(trees_.position.x,trees*.position.z)/size.y;
}
td.treeInstances=trees;*_
* //rotate detail layers*
* var num=td.detailPrototypes.Length;*
* for(int k=0;k<num;k++) {*
* var map=td.GetDetailLayer(0,0,td.detailWidth,td.detailHeight,k);*
* var newmap=new int[map.GetLength(0),map.GetLength(1)];*
* for(j=0;j<td.detailHeight;j++) {*
* for(i=0;i<td.detailWidth;i++) {*
* newmap[td.detailHeight-1-j,i]=map[i,j];*
* }*
* }*
* td.SetDetailLayer(0,0,k,newmap);*
* }*
}
Aw man it got me excited , I put the script in and realized it doesn't slowly rotate.. Just 90 degrees at a time. haha. Cool stuff but I want it to slowly rotate. Probably not possible eh?
– DremandHi, Noob here. I've added your script to my terrain but do not see how to click "Rotate 90 Deg" in your menu multiple times. Can you provide more information? Thanks!
– ughdeebThis script is great, although it rotates the trees the wrong way for me (90 degrees in the other direction). I don't know if it does this for other parts of the terrain since I'm only using trees, but it was easy to fix. For anyone else experiencing this problem, just replace line 34 with this: trees<em>.position = new Vector3(trees_.position.z, 0, 1 - trees*.position.x);*_</em>
– ollaxeSorry for replying on such an old question, but what do I do with the script? where do I have to put it so that it works?
– sjameselvisNo, you can't rotate the terrain. It's not possible to tilt it, or to rotate it around the Y axis.
This is largely due to the many optimisations built-into the terrain engine code, which rely on it maintaining a fixed orientation.
Yes of course you can rotate the camera! :-) it would be a slightly bizarre 3d engine if you couldn't.
– duckBy modifying the camera's transform.rotation property yourself, by adding one of the pre-made camera scripts, or by Animating the camera using the animation system.
– duckAnother update, if i create another rigid body above where my arrow collides, that rigid body will fall until it hits that spot and then stop as if its being held up by something... [167536-untitled1.png|167536]
– markemicekThere are several answers here already, but they are of different opinions and I believe if combined will give a good answer.
Short Answer - Yes you can, but you shouldn’t.
Long Anser -
As demonstrated by @techstig you can indeed to it. However as mentioned by @duck you really shouldn’t because the terrain is optimized for a performance. Also mentioned in the comment section of duck’s post it is better to simulate rotation. This can be done by rotating the Camera or even rotating everything except the actual terrain.
For example if you put everything under a singular object, you can have a simple transform.rotate() to rotate everything., since everything will be a child of this object.
it seems that attaching the terrain to a game object and trying to rotate it yields odd results... often translations I am trying to get a ball to roll down a bumpy hill... so i think i need a work around to have both a hill , and a bumpy road
– richardgengleYou cannot rotate the terrain, however, you may be able to pull off the illusion of rotated terrain using Assets->Create->Render Textures (Pro Version)
You can render texture from what a camera sees onto a plane of terrain and rotate the plane. It isn't perfect as it is clearly 2D at certain angles, but at the right angle or with the right use it may work.
I really wish they'd introduce terrain that can rotate too :)
Man that's weird. Do you have so many objects in your scene, that you cannot find the one responsible? It has to be a collider, surely. Does the red brick keep falling if its collider is set to trigger? What about adding a script to the red brick and debugging the colliders it collides with while falling. Something like OnCollisionEnter (Collison collision) { Debug.Log(collision.collider.name); }
– BlaBuWhat i have been able to do is scale 2d array values to make a slope.
like , psuedo code
for i…
for j [in for i]
terain height[ij] = 1-1/[max ct]
ter.sethts
Thanks, works fine.
– ivan111