- Home /
animating terrain texture question
When I was playing around in the terrain editor and accessing the edit terrain texture function, one of the things I did was scroll the texture's tile offset which created a nice effect of the ground texture moving in one direction.
I'm trying to figure out how to do this in code so it will animate like that in runtime. I've done some research on the terrain and the closest thing I've found was this: http://answers.unity3d.com/questions/285816/change-terrain-texture-and-tree-at-runtime.html which basically tells me that I need to access each individual alphamap by iterating through a copy of the terrainData's alphaMaps and then setting the alphaMaps on the terrainData to the copy after modifying it.
It's also clear that you can change between two textures, but I was wondering if it would be possible to constantly change (every frame) to a new texture, with 60 textures total (each one with a tile offset of an additional 0.0167 (1/60th))
I was thinking of extending the method listed above but I can't find out how to add textures to the splats array of the terrain without painting them all on one by one.
Any suggestions?
Answer by memelotsqui · Dec 02, 2013 at 06:59 AM
I made some research on this too, wanted to make some kind of water refractions, but my framerate went pretty low with what I found
var terrain:Terrain;
var splatPrototypes : SplatPrototype[];
function Start () {
splatPrototypes = terrain.terrainData.splatPrototypes;
}
function Update () {
splatPrototypes[2].tileOffset.x+=0.1;
//terrain.terrainData.splatPrototypes[2].tileOffset.x+=0.1;
terrain.terrainData.splatPrototypes=splatPrototypes;
}
In my case splatPrototypes[2] is the texture i want to offset, (Which is the third texture on my Terrain paint textures)
I tried accessing the tile offset directly (terrain.terrainData.splatPrototypes[2].tileOffset.x+=0.1;) but for some reason I can only affect it by changing the whole array, which is in fact, a framerate killer, but for now this works to offset the texture, hope someone finds a better solution :)
Your answer
Follow this Question
Related Questions
Terrain.SetAlphamaps Question 1 Answer
Texturing terrain at runtime 1 Answer
Paint Grid Texture 1 Answer
SetPixel() on Terrain 0 Answers
Resources.Load() don't loads texture in standalone build, when in unityeditor it does 1 Answer