the tree falls incorrectly by the player’s direction
mouse.Button1Up:Connect(function()
if mouse.Target then
local TreeModel = mouse.Target.Parent.Parent :: Model
local Size = TreeModel:GetExtentsSize()
local Pivot = TreeModel:GetPivot()
local Bottom = Pivot + Vector3.yAxis * (-Size.Y/2)
local Top = Pivot.Position + Vector3.yAxis * (Size.Y/2)
local directionOfFail = (Vector3.new(Bottom.Position.X, HumRoot.Position.Y, Bottom.Position.Z) - HumRoot.Position).Unit
local FallPos = (Bottom.Position + directionOfFail * Size.Y) - Top
RayCast:Change(Enum.RaycastFilterType.Exclude, {TreeModel, workspace.Ray})
local RayResult = RayCast:Cast(Top, FallPos.Unit*100)
if RayResult then
local angle = GetAngle(Bottom.Position, Top, RayResult.Position)
local lastCF = Pivot :: CFrame
local originToPartTransform = Bottom:ToObjectSpace(lastCF)
for t = 0, 1, .01 do
local X = angle * directionOfFail.Z * t
local Z = angle * (directionOfFail.X*-1) * t
Bottom = CFrame.new(Bottom.Position) * CFrame.Angles(X, 0, Z)
lastCF = TreeModel:PivotTo(Bottom*originToPartTransform)
task.wait()
end
end
end
end)
I’m bad at math