Search Unity

Question Tree Chopping - Masking Cuts and Falling Trees - Survival

Discussion in 'General Graphics' started by ratneshpatel, Jul 25, 2020.

  1. ratneshpatel

    ratneshpatel

    Joined:
    Oct 10, 2017
    Posts:
    21
    I am looking to implement Tree Chopping mechanics for my survival game.
    Requirements:
    1. When player uses its axe and does swipe animation, the tree gets chopped and cut is made incrementally (like a hole in the mesh)
    2. After certain amount of swipes the tree gets chopped at the cut and falls using Physics.
    3. The cut is made always at fixed height from the bottom point of the tree and during animation the player controller capsule adjusts so that the cut is made at the the given height.
    4. Similar kind of tree chopping system can be seen in The Forest game. Following is the screenshot:
    upload_2020-7-25_14-56-44.png

    My Approaches and Problems I am facing:

    1. Creating a Depth Mask Object at the Cut position:
    • In this approach I place a rectangular mesh at the point of cut. I set its ColorMask to 0 making it invisible and setting its ZWrite to On so it writes to Depth Buffer. I set the render queue of the alpha mask to Geometry - 1
    • I then add a rectangular mesh in the void created by the alpha mask and set its render queue to Geometry - 2 so that it is drawn before the Mask void is drawn.
    • The problem with this approach is that Anything behind the tree is not rendered in the groove of the tree and directly the skybox color is displayed.
    2. Placing a Replacement Tree mesh
    • Hiding the tree from terraindata and putting a new tree prefab (which is similar to the existing tree but has additional submesh of the groove) in place of the tree. Then gradually hide the groove outer face renderer to show the inner groove which is modeled in the Tree mesh.
    • As the tree size changes the cut height from the ground changes creating problems as for each size I have to create new meshes with groove mesh near the trunk.
    3. Using Shader Clip function
    • I know we can use clip function inside the shader of the tree to clip meshes or put some dark color at the cut.
    • I don't how to do this. I think the problem with this is then all the trees have a new shader and don't know if Unity allows for changing the shader of the tree in the terrain system.

    None of the above ideas work very well, some in fact just don't work.I would be grateful if you can share any ideas about how I might achieve this kind of chopping system.
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Maybe just slice the mesh at first chop, deform the vertices near the chop a bit more with each swing ..emit some particles for dust/woodchips/barkchips(?), project some kind of decals, could have a procedural mesh between the pieces if you want it to look better or use some prefab chunks.. I don't know just thinking out loud.

    As for mesh slicing itself, there are probably free approaches around but here's an example of what I mean that I grabbed some time ago - I haven't actually used it / can't vouch for this in particular.
    https://assetstore.unity.com/packages/templates/tutorials/mesh-slice-template-173470
    time_saver.jpg
     
  3. danilec1313

    danilec1313

    Joined:
    Mar 10, 2018
    Posts:
    6
    Hello!
    You can check this asset: https://assetstore.unity.com/packages/slug/209346

    It works with Unity trees or SpeedTrees with a standard Unity wind. Also can be useful for any other tree (check the description of the asset about limitations).
    Have a nice day!