Hello guys. I want to make game, where you can cut logs. I did axes, handsaws, but I got some problems with machines, like circular saw. The main problem that it cuts in wrong place, if log is rotated, like:
Red is saw, black is log. Assume that log goes down onto saw.
You can see here, that saw can hit log here:
But, in fact, log is cut like this:
You can see there 2 orange lines. That’s because it somewhy cuts log randomly. It can cut either lower or higher.
And there’s code I use:
local SawCFrame = Saw.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/2, 0)
local AngleToSaw = -SawCFrame:Inverse().RightVector:Dot(Log.CFrame.RightVector)
if AngleToSaw > 0.95 or AngleToSaw < -0.95 then
--Pillar cut here. Works fine
else
local SawMark = SawCFrame:Inverse() * Log.CFrame
if (SawMark.Z < Log.Size.X / 2 and -SawMark.Z < Log.Size.X / 2) then
local Size1 = SawMark.Z + Log.Size.X / 2
local Size2 = Log.Size.X - Size1
local Offset1 = (Size1 - Log.Size.X) / 2
local Offset2 = (Log.Size.X - Size2) / 2
local Pillar1 = Instance.new("Part")
Pillar1.Material = Log.Material
Pillar1.Color = Log.Color
Pillar1.Shape = Enum.PartType.Cylinder
Pillar1.Name = "Log"
Pillar1.Size = Vector3.new(Size1, Log.Size.Y, Log.Size.Z)
Pillar1.CFrame = Log.CFrame * CFrame.new(Offset1, 0, 0)
local Pillar2 = Pillar1:Clone()
Pillar2.Size = Vector3.new(Size2, Log.Size.Y, Log.Size.Z)
Pillar2.CFrame = Log.CFrame * CFrame.new(Offset2, 0, 0)
Pillar2.Color = Color3.fromRGB(255, 0, 0)
Log:Destroy()
Pillar1.Anchored = true
Pillar2.Anchored = true
Pillar1.Parent = workspace
Pillar2.Parent = workspace
end
end
Can someone tell me, why saw behaves like this, and how I can fix it?
Some notes:
I use CFrames and Touched events here. I don’t want to use raycasting for anything here. Only CFrames and math.