How to chop the tree like lumber tycoon 2

I want to make system that chop the tree like lumber tycoon 2
However there’s a ploblem. I can’t find CFrame I need to find
Who can make that CFrame value

1 Like

raycast server side

see if hit instance is a tree

create progress on hit position that wraps the tree

in a nutshell

i mean i need to find mark cframe

what

in lumber tycoon 2, if you chop the tree, it will leave a mark on that tree. I need to find the mark cframe

create a part
name it whatever
parent it to the hit tree
set its position to raycast position, then center it on the log that was hit
now you can get its cframe

taking the ray casts hit positionminus the hit instance position should give you the offset from where the hit instances position. Now you can use that offsets Y to figure out at what height the mark should be or

local markPosition = hitInstance.Position + Vector3.yAxis * (hitPosition.Y - hitInstance.Position.Y)

that wont correct if you chop a rotated tree

then you’re gonna have to make it work with rotated trees, probably something to do with subtracting orientation or whatever

simply make it use the hitInstances CFrame instead

local markPosition = hitInstance.CFrame * CFrame.new(Vector3.yAxis * (hitPosition.Y - hitInstance.Position.Y))

can hitInstance = mouse.Hit instead of get raycast pos?

it would make it a bit more difficult i believe, but yeah you could replace it with mouse

local hitInstance = mouse.Target
local hitPosition = mouse.Hit.Position

I tested and im having a ploblem. If i chop a rotated tree, the mark will have a offset, the further camera zoom is, the bigger offset it is. How can I fix it

could you show me the part where you calculate the position and create the part?

here

local repStorage = game:GetService("ReplicatedStorage")
local wood = {}

function wood.Chop(plr : Player, target, woodName)
	local mousePos = repStorage.Remotes.GetMouse:InvokeClient(plr).Position
	local targetCF : CFrame, targetSize = target.PrimaryPart.CFrame, target.PrimaryPart.Size

	local woodUp = repStorage.Woods:FindFirstChild(woodName):Clone()
	
	local mousePosOnPart = targetCF * CFrame.new(Vector3.yAxis * (mousePos.Y - targetCF.Position.Y))

	local newP = Instance.new("Part")
	newP.Parent = workspace
	newP.Size = Vector3.new(5,1,5)
	newP.CFrame = mousePosOnPart
	newP.Anchored = true
	newP.CanCollide = false

	local topCF = targetCF * CFrame.new(0,targetSize.Y/2,0)
	local distance = (topCF.Position - mousePosOnPart.Position).Magnitude
	local upCF = mousePosOnPart * CFrame.new(0, distance/2, 0)

	woodUp.PrimaryPart.Size = Vector3.new(targetSize.X, distance, targetSize.Z)
	woodUp:PivotTo(upCF)

	local woodDown = repStorage.Woods:FindFirstChild(woodName):Clone()
	local bottomCF = targetCF * CFrame.new(0,-targetSize.Y/2,0)
	local distance2 = (mousePosOnPart.Position - bottomCF.Position).Magnitude
	local downCF = mousePosOnPart * CFrame.new(0, -distance2/2, 0)

	woodDown.PrimaryPart.Size = Vector3.new(targetSize.X, distance2, targetSize.Z)
	woodDown:PivotTo(downCF)

	woodUp.Parent = workspace
	woodDown.Parent = workspace
	target:Destroy()
end

return wood

Ohh i realized now that if a part is rotated a lot it will start breaking since it doesn’t account for that in the calculation. Try this instead, it should hopefully work

local mousePosOnPart = targetCF * CFrame.new(Vector3.yAxis * targetCF:PointToObjectSpace(mousePos).Y)

this works so well! Thanks for helping me how to get it!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.