- Home /
3D Unity-Terrain realtime modifier
This question is outdated and no longer applies.
I'm trying to build a new mode for my upcoming game and require help, I need to find a voxel engine or programming solution for unity terrain to edit (at runtime). I also require help to be able to initiate game objects on a key press (at runtime).
Thanks, Harley
Answer by Spinnernicholas · Dec 05, 2013 at 08:44 PM
You can calculate the point where the projectile hit the mesh. And then loop through all the vertices changing them.
You would need some sort of function to change them.
void ChangeVert(Vector3 hit, Vector3 vert)
{
//This is 3D distance, you may want 2D distance.
if((vert - hit).sqrMagnitude() < maxAffectDistance * maxAffectDistance)
{
//Change Vert
}
}
Then iterate through them modifying them.
You may want to do other bookking, like tracking the differences from the original to set a max deformation range.
Some of this functionality exists in the built in Terrain type, but I've never tried modifying it at runtime.
Answer by writestuff77 · Dec 09, 2013 at 04:29 PM
sorry for the long reply(because my data became corrupted and i had to load a backup)I am not a great programmer(but i am trying to teach myself)So please can you put this in a script if i told you the details (like vertices and position) could you put it in a script or should i just ask around if you dont know???
That's more work than I have time for. $$anonymous$$esh vertices are stored in an array, you will have to iterate through it and apply your deformation function. The main problem is, that is the easy part.
Deciding what your deformation function is and integrating the whole thing into the rest of the game are the hard parts.
Your answer
Follow this Question
Related Questions
Please help with player selection screen 2 Answers
How to do a 2D raycast within a Canvas? 0 Answers
UI Click pass through 1 Answer
Mouse and Keyboard highlights UI element at same time 0 Answers
Getting reference to TouchScreenKeyboard on mobile devices 2 Answers