[Unity3D Hex Map Game Dev] 9: How Much Wood Would a Woodcutter Cut?

Опубликовано: 03 Апрель 2026
на канале: Re: cOg Mission
1,243
23

Hello Unity fans. Today we’re resuming the process of getting our woodcutter to chop down and harvest trees. Given that we’ve already managed to get him to find a tree and walk up to it in our last video, this may seem straightforward, but there are a few things to consider in the bigger picture in order to let it all fit seamlessly into the system. These include his position on the terrain in-between steps, possible interaction with objects and other units, and how much fine detail to focus on visually. Note that the first screen captures in this video still have the penguin-like walking animation in place – I corrected this only later, as described in the previous video, which you can find in the link in the upper right and down below. But let’s get going with this one.

Part0 (Introduction):    • [Unity3D Hex Map Game Dev] 0: Introduction...  
Part1 (Hexes to Water):    • [Unity3D Hex Map Game Dev] 1: Hexes to Water  
Part2 (Features and Textures):    • [Unity3D Hex Map Game Dev] 2: Features, Te...  
Part3 (Units, Visibility):    • [Unity3D Hex Map Game Dev] 3: Units, Pathf...  
Part4 (Random Maps):    • [Unity3D Hex Map Game Dev] 4: Creating Ran...  
Part5 (Post Processing):    • [Unity3D Hex Map Game Dev] 5: Post Process...  
Part6 (Resource Gathering):    • [Unity3D Hex Map Game Dev] 6: Automated Re...  
Part7 (Spinning Selector):    • [Unity3D Hex Map Game Dev] 7: Spinning Obj...  
Part8 (Preparing for Resources):    • [Unity3D Hex Map Game Dev] 8: Preparing fo...  

---*----* My Playlists *----*---
Unity Journey Of Discovery (Tutorials):    • Unity Journey of Discovery: Hello World! V...  
The Main Course (Maths and Science Concepts Explained Visually:    • Sun, Earth and Moon: Introduction and Scale  
Eco-Pool Natural Swimming Pool (Build and Progress):    • Green/Eco/Natural Pool, Part 1: Planning t...  
4K Treats (Ultra HD content):    • Marine Life Photos Part 1 4K UHD  
Finger Snacks (Shorter, Unclassified Videos):    • Ribbon Eel (Rhinomuraena Quaesita) Swimmin...  
*----*----*----*----*----*----*----*

When our woodcutter has found his target, we subtract a buffer from the tree’s position, in the direction of the hex the woodcutter would approach from, so that he doesn’t walk to right on top of the tree, but have some space to swing his arms. We make this a parameter, so that we can adjust it in one place should any of the dimensions or scales change. So, we can set up different locations on the target hex for the unit to walk to, instead of the middle of the hex, and the gradual start and stop functionality still works. We see that the axe connects with the trunk of the tree no matter from which direction it was approached, so our offset is working nicely. But the hits are not yet registering, so the trees never fall over. In order to string all these actions and effects together in a sequence, we need a list of possible actions and effects, as well as some way to manage them and decide when which one should happen. As we did for the possible resource types in the previous video, we create another enum for all the possible actions. For now, we’ll only implement a few of them, and let’s hope we don’t have to get to “dying” soon. So, we now store the previous and current actions to allow us to write some logic to determine the sequence of actions to take. On every frame, we test whether the unit is ready for orders. If he is we let him select the next action to perform. If there was no previous action, so when the unit starts out, we let him search for a tree. After finding a tree, we let him travel to the tree, and start chopping when he gets there. When he’s chopped the tree down, he steps back from it to get out of the way, after which he searches for the next tree. We will add some more steps here later. Each time a new action is set, we backup the previous action, and indicate that the unit is not ready for orders anymore, and that the current order has not completed successfully yet. Only once the current order has been completed do we move on to the next. But how do we know when an order has completed? We implement a system of sending instructions that should be executed once the action has been completed along with the call for action. These are, incidentally, also called actions, but they are Unity’s formal actions. So, we see, once a resource has been found, whatever action was passed along will be executed at this point in the algorithm. In this case, the action we want to be performed is merely setting the flags to indicate that the current action has been completed successfully. Since the last order has been successfully completed, a new order will be selected based on the previous order.