Search Unity

can you realtime terraform inside a Unity game?

Discussion in 'Editor & General Support' started by erikc, May 6, 2008.

  1. erikc

    erikc

    Joined:
    Mar 18, 2006
    Posts:
    9
    hi it seems to me that you can create or at least change the size/scale or mesh height of landscape while inside unity editor so surely one can do terraforming inside a Unity game?
    Has anyone done this or have examples or links?

    Judging by the below
    http://forum.unity3d.com/viewtopic.php?t=9147&sid=af0637764a49ede78e6920a9795bb40b
    it is possible?
    Or does it involve much C# or Javascript?

    The game idea is: 2 running men, run across the globe and create or move landforms or obstacles to hinder each other's progress. For the prototype, rather than rely on networking (which has trouble with multiple cameras?) we would have the 2 players share a keyboard.

    thanks in advance
    Erik
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, use GetHeights() and SetHeights(). How much scripting is involved depends on what you're doing exactly.

    --Eric
     
  3. erikc

    erikc

    Joined:
    Mar 18, 2006
    Posts:
    9
    thanks, I sent youa private message :)
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    A while ago I did a modification of this thing where you drop bombs on the ground to make scorch marks, except it makes craters in the terrain too, just as a little test, but I never posted it. So I cleaned it up a bit and here it is. You can't see the scorch marks or the crosshair cursor on the terrain, because projectors don't work on terrains...yet.... (Although, scorch marks could also be done by altering the splatmap data instead of using a projector.) If you wanted to make hills instead of craters, then you'd just add instead of subtract. And of course, there are plenty of ways to make hills and valleys; I used a texture for the crater here because it seemed the easiest way at the time.

    Edit: projectors work on terrains as of 2.1, so you can see the crosshair and scorch marks now, yay! (Also see the comment in the Cursor.js script.)

    Edit2: version that works in Unity 4: View attachment $bombterrain4.unitypackage

    --Eric
     

    Attached Files:

  5. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    262
    This is awesome - I had been wondering if real time terrain deformation worked and this is great to play around with. Thanks for posting!
     
  6. cwflyer8

    cwflyer8

    Joined:
    Mar 18, 2009
    Posts:
    18
    What about animating the position of a normal map to convey a crater?
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    unless you have an own terrain shader, there is no normal mapping on the terrain
     
  8. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    hi all,

    I'd love to see BombTerrain.unityPackage in action but it seems to be broken as it was created some time ago.

    I'm trying to get it working without luck as yet.

    Anyone else feel like giving it a try?

    Cheers


    Jeff
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make the blank, crater, and splat textures readable, like the error message says. Then it will work.

    --Eric
     
  10. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    Heya Eric,

    Many thanks - working great!!

    This is a great technique - wonderful package.


    Cheers


    Jeff
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Also I updated the unitypackage. (Apparently the file size is small enough not to be affected by the attachment bug that's been affecting the forums for a while now.)

    --Eric
     
  12. deudtens

    deudtens

    Joined:
    Apr 17, 2011
    Posts:
    1
    Hi !

    At first, thanks to the author for the terraforming scene, it's great !

    I discovered Unity yesterday and I have a question : I transformed Eric's scene to use it with a first person controller. I added a function creating crater with mouse button 1, and a hill with mouse button 2. The problem is that when I create a Hill under my own feet, I fall down under the terrain. I'd like my character to stay over the flooor when it's getting higher. How to do that ?

    Alternate question : instead of suddenly being modified, i'd like the terrain to grow (or decrease) smoothly. Is it possible ?

    Sorry for my english, I'm french !

    Thank to all af you !
     
  13. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Hi Deudtens, I haven't looked at the code at all yet, but I'm guessing you could just use a newHeight variable to set the height as. Then as long as you hold down the left mouse button, set the height to be newHeight and increase this variable by [arbitrary number], multiplied by Time.deltaTime;.