Hello, I am wondering how part:resize() works.
To my understanding, an example code of this looks like
local part = script.Parent
part:Resize(Enum.NormalId.Left,2)
Where the Enum.NormalId is the direction, and the 2 in this case is the amount to add it by.
Specifically, How would I implement it into this bit below:
-- raycast
local raycastResult = workspace:Raycast(bottomAttachment.WorldPosition, direction * 10, raycastParams)
-- distance
local ADD = 0 -- no change if no hit.
if raycastResult then
-- distance between TIPTOP and the raycast hitpoint
local distance = (raycastResult.Position - tipTopAttachment.WorldPosition).Magnitude
ADD = distance * -1 -- subtract, because we are adding stuff.
-- print statements
print("Distance from TIPTOP:", distance)
print("ADD:", ADD)
end
end)
Here, ADD is the amount I want to shrink the blade, so I multiplied by -1.
But any attempts I’ve made shrink it too much, or too little, or from both sides.
Below is a video of the current behavior, which I think is good, it gets the correct distance.
If anyone has any improvements, or any insight, please reply to this topic, I’ll be checking it often.
In addition, here’s the rest of my code:
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local blade = script.Parent.Blade
local tipTopAttachment = blade:WaitForChild("TIPTOP")
local bottomAttachment = blade:WaitForChild("BOTTOM")
local normalSizeZ = 9.969 -- default size
local previousADD = nil -- previous value tracking
RunService.Heartbeat:Connect(function()
-- direction
local direction = (tipTopAttachment.WorldPosition - bottomAttachment.WorldPosition).Unit
-- raycast
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
-- dont hit these
local playerParts = {}
for _, player in ipairs(Players:GetPlayers()) do
local character = player.Character or player.CharacterAdded:Wait()
for _, descendant in ipairs(character:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(playerParts, descendant)
end
end
end
local ignoreParts = CollectionService:GetTagged("IGNORE")
raycastParams.FilterDescendantsInstances = ignoreParts
-- raycast
local raycastResult = workspace:Raycast(bottomAttachment.WorldPosition, direction * 10, raycastParams)
-- distance
local ADD = 0 -- no change if no hit.
if raycastResult then
-- distance between TIPTOP and the raycast hitpoint
local distance = (raycastResult.Position - tipTopAttachment.WorldPosition).Magnitude
ADD = distance * -1 -- subtract, because we are adding stuff.
-- print statements
print("Distance from TIPTOP:", distance)
print("ADD:", ADD)
end
end)