How to make a choppable tree like in lumber tycoon 2?

I’m trying to make a system to chop down a tree exactly where you click.

I’ve looked everywhere but can’t seem to figure it out, all I can find are videos showing you how to just un anchor the tree when you click it.

I’m not trying to ask for a full script, I would just like to know how to generally go about doing it.
EDIT: I already know how to detect where the mouse is I just want to know how would I cut the tree exactly where they hit it.

4 Likes

Well, I’d suggest, when the tool is equipped, upon click, it sets off debounce, and plays the animations, then it fires the mouse’s target through the remote. The server checks the distance between the tool’s tip and the tree and so on.

1 Like

I already know how to check the magnitude between the player and the tree, I’m just trying to figure out how to break the tree where the player hits it. Thanks for replying :grinning:

1 Like

You can do this:

Code Used

e.Velocity = e.CFrame.LookVector * 10

Explanation:

Weld a part to another, when it’s time to break, unweld the parts, then add a velocity to the part you want to make fall over.

3 Likes

Maybe make the tree have around five parts welded together, when the player cuts the tree, detect which part the player hit and where the closest surface of that part is (top or bottom) destroy the weld, etc.

Just a thought, might not be too effective and would probably cause more lag.

Similar to @Ra_f 's code, just with more parts.

1 Like

Use treePart.CFrame:pointToObjectSpace(mouseClickPos) and take the Y component of that vector (assuming your treePart is oriented so that Y is the tall axis) to get the height along the length of the part that the cut should be made.

Once you have the height the cut needs to made, delete the original tree part and replace it with two parts above and below the cut line, with adjusted Y sizes to make the cut work.

Rebuild the welds between the bottom and top part and their branches.

64 Likes