Search Unity

Approaches to tree felling

Discussion in 'Getting Started' started by viveleroi, Jun 7, 2018.

  1. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I'm working semi-low-poly game and am toying around with how to handle "tree felling".

    My goal is have a tree "fall" when it's been cut down but I'm not sure on the best approach. Ideally, there would be a stump left in the ground and the tree trunk/leaves itself would fall, hit the ground, and vanish leaving logs behind. Somewhat like Zelda: Breath of the Wild.

    As for the visuals - I'm thinking I'll need two prefabs - the trunk, and the tree trunk/leaves. The tree stump and trunk will spawn in-world as if they're one (not sure how easy it will be to make them look like one mesh - I may need a third prefab). When they "cut down" the tree, I leave the stump where it spawned and "tip over" the trunk.

    Is that a good approach or is there a better solution?

    What's the best way to "tip over" an object? I'm thinking it will need a rigidbody with a force applied above the center of the mass (or maybe torque?).

    I thought about animation but I want the tree to fall in the opposite direction it was cut and I want the fall itself to be somewhat physics-driven.
     
  2. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hi viveleroi,

    Not sure if I'll be able to provide the best advice (so if someone disagrees with anything I say, go with them!), but I believe you're on the right track.

    To have the tree and the stump separate, in the same space at the same time, have them both visible and have both items look like they're connected depends on a couple of factors.
    1. Are they going to be constructed at the same time (i.e. in blender as one object, then split) as this may cause a visual seam to appear.
    2. Are the tree going to be affected by any of physics that aren't involved in the tree felling itself? As in wind, explosions, driving a car into it etc. If not, then they should be all good. If you are planning to include these sorts of interactions then your problems will increase because, if they are 2 separate items you can't allow the meshes to come apart anywhere to produce a visible seam.
    The first one is easy to overcome - more of a workflow note, simply make a whole tree in blender, then slice it into 2 parts and the right point and just add faces.. But the second depends on what you want to be able to do in the environment.

    The leaves could be either attached to the tree as parent-child and then when the tree is felled they could be uncoupled - this will allow the leaves to actually fall (provided they have rigidbodies attached). Or you could have the ones on the tree stay there and simply use a particle system to throw out some leaves.

    But, as far as I can see, you have a good idea of what to do already. Perhaps chuck together some ugly prototypes and test...

    As for the tipping you want to somehow have an anchoring point connecting the tree to the stump until the anchor reaches a certain angle. A couple of ideas that you can research or test are as follows:
    1. An invisible collider could be instantiated just on the other side of the tree for it to hit and roll over. But this is going to be ugly, fiddly and IMHO not an elegant solution.
    2. Use a hinge joint. This will allow you to hinge the tree off of the stump AND even set a breaking limit for the torque or force that will be applied by the tree falling to the ground. Check out the following resources for more information:

    I have a feeling that I've just muddied the waters more than actually make things clearer. But if that is the case, hopefully someone else will be able to help you more than I have (I mean, they can't do any worse, can they? Lol).
     
  3. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I appreciate your reply.

    #1) I've been learning blender so I will do them both at the same time and cut them, fix faces, etc.
    #2) Only physics on the trunk as if falls, no other physics needed.

    Your reply mirrors what I've been hearing on other forums so I think I'll try the two prefab approach and see how it goes.

    Someone on reddit suggested using animations to "start" the falling over process and then letting physics take over. That sounds like it's what you intended hinge joints for. How would you compare those approaches?
     
  4. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hmm, I didn't even think about animating the start.
    If you animate the beginning of the felling you get to sort the way it looks... however I think that will also mean that the tree will only fall in one direction no matter where the player is facing the tree from.

    I was suggesting that you apply a force to the rigidbody of the tree, and with it's base being attached (for a short while at least) to the stump it should give you the felling effect.

    Just make sure that whichever approach you go for you have the physics disabled for the tree until it's been fully cut...
     
  5. BrunoPuccio

    BrunoPuccio

    Joined:
    Dec 13, 2017
    Posts:
    22
    in Rust for example the falling tree is just an animation without any physics or anything, and in The Forest when you chop down a tree it instantiates a log with rigidbody above the trunk, you can just jump and push the log to choose where you want it to fall.
     
    Tset_Tsyung likes this.