Hi! I am trying to make a chopable tree where you can cut where ever you want, if you cut a piece of wood from the tree it becomes annother part and isnt a part of the tree anymore. What I mean by this is that it creates a new part with the same shape that has ben cut off (maybe I can use Instance.new here?). I already made a working chainsaw but I really dont know how to do a script for the tree. Does anyone got some ideas? Also the tree is a mesh, maybe I need to make a hitbox with invisible parts in the tree? Here´s a video which explains what I want to achieve:
I am not asking for whole scripts here but I need some parts of scripts or just some ideas that might help me.
So if u want to do something like this u need to get where the mouse has hit the log.
like this
local mouseHit = mouse.Hit.p
local ObjectCF = Target.CFrame:PointToObjectSpace(mouseHit) -- gets the cframe depending from the hit log
local SplitCF = CFrame.new(0,ObjectCF.Y,0) -- thats the split position, we use the ObjectCF to get the center of the log (Make sure your log size is longer at Y axis)
-- from here u just create the new logs
local newlog1 = Log:Clone() -- thats just an part saved somewhere
newlog1.Parent = workspace
newlog1.Size = Vector3.new(1,Target.Size.Y - math.abs(SplitCF.Y),1)
newlog1.CFrame = (Target.CFrame * SplitCF) * CFrame.new(0,newlog1.Size.Y/2,0)
local newlog2 = Log:Clone()
newlog2.Parent = workspace
newlog2.Size = Vector3.new(1,math.abs(SplitCF.Y),1)
newlog2.CFrame = (Target.CFrame * SplitCF) * CFrame.new(0,-newlog2.Size.Y/2,0)
If you still really want to make it work with meshes you could have certain “points of interest” So say you cut one of the stem lines then it will directly cut off the middle intersection instead of where you hit, whilst this may not be exactly what you want you can then essentially have a table of “point of interest” meshes to apply to the cut off part. Still highly recommend that you just don’t use meshes if you want this kind of behaviour as finding a solution to the most desired visuals would pose a challenge.