Search Unity

How did Worms make craters in terrain on impact?

Discussion in 'Scripting' started by naorgueva, Jan 16, 2020.

  1. naorgueva

    naorgueva

    Joined:
    Apr 11, 2019
    Posts:
    25
    Hi,

    Can i manipulate terrain height and create an impact crater?

    (and like in worms it needs to work with physics)

    Thank you in advance!
    Naor
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Well Worms had a texture map that it just erased pixels from, and its physics engine was written to collide with texture maps. Unless you're up for writing your own physics engine, then "how worms did it" won't be the best guide, so let's figure out a close analog in Unity.

    First question to ask here is: 2D or 3D?

    Second question: If in 3D, do you need it to support overhangs, or not?
     
  3. naorgueva

    naorgueva

    Joined:
    Apr 11, 2019
    Posts:
    25
    3d

    overhangs?
     
  4. naorgueva

    naorgueva

    Joined:
    Apr 11, 2019
    Posts:
    25
    hoo overhang!

    i will start with the most simple way right now
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    So, by default, Unity's Terrain doesn't support overhangs. That is, if you dig a hole downward and then go left, you can't do that. More relevantly, if you blow a hole in the side of a cliff, that's not supported either - most likely, all the terrain above the hole would simply vanish. (I think Unity has added support for terrain "cutouts", but that's not a sufficient solution for destructible terrain.) If you want something Worms-style, you want overhang support, but if it's a more specific need where you might not be blowing holes in cliffs, then you may be able to use Unity Terrain for it.

    If you need to support overhangs, you'll need to go third-party; more specifically, you'll need a voxel terrain engine. There are several different options depending on your exact needs. Some are really basic, but open source, some cost money but produce really nice looking results, it's all up to you. Good news is that voxel terrain almost always will support being destroyed so you sort of get that functionality "for free".
     
  6. naorgueva

    naorgueva

    Joined:
    Apr 11, 2019
    Posts:
    25
    First of all thank you for your time and effort into answering me.

    I would like to know to go with no overhangs, then i will learn the more complex methods.

    so where do you think i should start?
     
  7. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    I'd probably make a black and white heightmap shaped like a crater, and when you have an explosion you subtract that heightmap from your terrain heightmap.
     
    StarManta likes this.
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,740
    If you take a look at my
    makegeo
    project it has a realtime terrain deformer hooked up to a cheesy FPS where you shoot bombs/grenades and pockmark the terrain.

    The demo scene is under
    TerrainStuff
    and I think it's called
    TerrainDamager
    . Just sync the entire project.

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo

    There's tons of notes / comments in the code. It's a bit fiddly to get right.
     
    StarManta likes this.