- Home /
terrain rotation
Is it possible and how can i roate the terrain?
Answer by techstig · Mar 05, 2012 at 02:57 AM
I 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!
Answer by duck · Apr 13, 2010 at 08:06 PM
No, 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.
By 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.
Answer by ChristmasEve · Sep 29, 2017 at 03:45 PM
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[i].position=new Vector3(1-trees[i].position.z,0,trees[i].position.x);
trees[i].position.y = td.GetInterpolatedHeight(trees[i].position.x,trees[i].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);
}
}
could this be modified to support an arbitrary rotation on any axis?
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?
It doesn't because it re-drawing/rotating the heightmap.
Hi,
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!
ah never$$anonymous$$d i see it up on the menu now. is there any way to duplicate just the one terrain? I have dupilicated a terrain and trying to rotate it to piece it together, but when i use your tool both terrains rotate 90 degrees.
This 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[i].position = new Vector3(trees[i].position.z, 0, 1 - trees[i].position.x);
Sorry 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?
Answer by Cornelis-de-Jager · Dec 02, 2018 at 04:06 AM
There 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
Answer by discoelf · Oct 08, 2011 at 07:59 AM
You 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 :)
The problem with that is that the render texture is highly pixelated
Your answer
![](https://koobas.hobune.stream/wayback/20220612162346im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a simple tree 1 Answer
Can't use tree brush tool 0 Answers
How Do You Add Terrains To Objects? 1 Answer
Procedural mesh artifacts 0 Answers
Imported terrain object - Do I need to apply settings for it to be recognised by game objects? 1 Answer