- Home /
I'd like to access terrain textures on a .obj terrain, any pointers?
Hi, I'm creating a demo for sound design and I want the character's steps to change according to the terrain's texture below the character (see http://answers.unity3d.com/questions/14998/how-can-i-perform-some-action-based-on-the-terrain.html , Ben Pitts' answer, since triggers would be a rather long route) but I just discovered that the level I'm using has a .obj terrain which I haven't been able to access via my C# scripts. Does anyone have a clue as to how I might go about this? I see I have access to a compiled shader but I don't really have a clue of how to modify it (assuming it's actually possible) to give me the values I'm looking for. I tried Obj2Terrain but I obtained a mesh with no textures, so it doesn't seem to be the right way. Thanks and cheers, F
You can raycast for pixel color or for mesh material and make decision based on that.
Ah, that sounds good; on to learn raycasting it is :) . Thanks for the tip. Cheers
Ok, got raycast working but I get null for the raycastHit.collider.renderer and can't find anything of much use in the debugger when I explore the raycastHit instance from the hardcoded terrain (not so from added meshes such as rocks or other props where I do get a renderer and triangleIndexes as expected). Any other ideas? Thx and cheers, F
$$anonymous$$ake just simple planar mesh with outlines of areas projected and tag them or use simple plane with color codded info and setup raycast matrix and collision layers corespondingly. Then you can ask unity for color code or area tag and process that info..
Ok, so I managed to make a plane under my terrain with the original terrains' splatmask and get the pixel's color value through raycasting (which I also use for detecting rock or other props that would affect the sound of footsteps). Oddly enough, the other terrain's splatmask gets imported inverted on the y axis (inverted from the original terrain, that is) and raycasting on something with a single negative scale value seems to invert coordinates within each triangle in the mesh. It's really odd, so I just created a second inverted tif and used that but if you know why this happens I'd like to find out. (to reproduce, create a plane with a white texture and scale values of 1,1,-1. Then setpixel() to Color.black under a walking FPS. Watch this in the editor from above and you'll see that the black lines are symetric to the FPS' path within each triangle). Anyhoot, thanks for your help, it's working now ;)