I want to shorten parts from only one face, The gif above shows my current method.
WHAT I’VE TRIED:
Moving the Cframe after changing Size property
my code:
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local tweenserv = game:GetService("TweenService")
local blade = script.Parent.Blade
local tipTopAttachment = blade:WaitForChild("TIPTOP")
local bottomAttachment = blade:WaitForChild("BOTTOM")
local deltsize = 9
local beam = Instance.new("Beam")
beam.Name = "LaserBeam"
beam.Color = ColorSequence.new(Color3.fromRGB(255, 0, 0))
beam.TextureMode = Enum.TextureMode.Stretch
beam.Parent = blade
beam.Attachment0 = bottomAttachment
beam.Attachment1 = tipTopAttachment
-- update
local TweenInfo = TweenInfo.new(0.01, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) --smooth
RunService.Heartbeat:Connect(function()
-- Calculate the direction from BOTTOM
local direction = (tipTopAttachment.WorldPosition - bottomAttachment.WorldPosition).Unit
-- raycast from the BOTTOM attachment in the Z-axis direction (10 studs max)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
-- ignore parts
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")
local finalIgnoreParts = {}
for _, part in pairs(playerParts) do
table.insert(finalIgnoreParts, part)
end
for _, part in pairs(ignoreParts) do
table.insert(finalIgnoreParts, part)
end
raycastParams.FilterDescendantsInstances = finalIgnoreParts
local raycastResult = workspace:Raycast(bottomAttachment.WorldPosition, direction * 10, raycastParams)
local newBladeSizeZ
if raycastResult then
--getdistance from hitpoint to bottomattachment
local distance = (raycastResult.Position - bottomAttachment.WorldPosition).Magnitude
newBladeSizeZ = math.min(distance, 10) -- length to a max of 10 studs
else
--defaultcase
newBladeSizeZ = 10
end
local targetProperties = {
Size = Vector3.new(blade.Size.X, blade.Size.Y, newBladeSizeZ),
}
local tween = tweenserv:Create(blade, TweenInfo, targetProperties)
tween:Play()
end)
The issue with changing the position is changing the cframe. the blade is supposed to follow your mouse, which changes the position frequently.
Changing the Cframe of the blade WHILE moving is really tedious, and I can’t seem to figure it out.
I was also suggested to use Part:Resize(), But had no luck with it.
If anyone has a solution or any improvements to my implementation, I am open to them.