- Home /
Change texture on terrain based on Vector3 at runtime
I want a way to change the texture of my terrain at specific positions during runtime. For example, if a rock is randomly generated at 23,0,34 at the start of the game, I want a 1x1 dirt patch texture to appear under the rock. I just need the code that would help me convert vector3 positions to whatever positions the terrain uses so I can tell the terrain what and where to paint when I generate my level.
I found this post: https://alastaira.wordpress.com/2013/11/14/procedural-terrain-splatmapping/ which seems to be about changing textures based on the height of the terrain. Since I have a totally flat terrain, it doesn't seem relevant to my project. I'm using Unity 5 and writing in c#.
Any advice?
There is doc that explains how to convert the Vector3 pos to terrain, I think it's normalized (0 to 1) on terrain scale across x and z. I'll post if I can find it.
See this http://answers.unity3d.com/questions/409408/heightmap-to-world-location.html
I haven't looked at the splatmap in a while, is it using the x,y
I've seen this post. Still a little confused as to how to actually implement the code for my project. It seems to be taking height map information into account, but I don't think that's what I need???
I think you'll need to combine the snippets on those pages and fill the gaps, I don't have straight code (thus no Answer, just comments). Other links that might help:
http://forum.unity3d.com/threads/modify-terrain-texture-at-runtime.108885/
http://answers.unity3d.com/questions/178661/update-terrain-alphamap-at-runtime-makes-my-game-c.html
http://answers.unity3d.com/questions/7985/modifying-terrain-splat-texture-at-runtime.html