I want to shorten parts from only one face. Here is my current implementation:
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)
Above is a GIF on the current behavior.
How can I adjust the CFRAME to show as scaling from the top only?