From 7481ffb0c95018ec9e5986598109601b2a9e3e58 Mon Sep 17 00:00:00 2001 From: Wil <63251107+wilyt1@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:09:25 -0400 Subject: [PATCH] Update blink and thru to ignore non-collidable parts --- Cmdr/BuiltInCommands/Debug/blink.lua | 28 ++++++++++++++++++++++++++-- Cmdr/BuiltInCommands/Debug/thru.lua | 28 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Cmdr/BuiltInCommands/Debug/blink.lua b/Cmdr/BuiltInCommands/Debug/blink.lua index 602901f9..01b82b2d 100644 --- a/Cmdr/BuiltInCommands/Debug/blink.lua +++ b/Cmdr/BuiltInCommands/Debug/blink.lua @@ -1,3 +1,17 @@ +local CollectionService = game:GetService("CollectionService") + +for _, instance in workspace:GetDescendants() do + if instance:IsA("BasePart") and not instance.CanCollide then + instance:AddTag("RayBlacklist") + end +end + +workspace.DescendantAdded:Connect(function(descendant) + if descendant:IsA("BasePart") and not descendant.CanCollide then + descendant:AddTag("RayBlacklist") + end +end) + return { Name = "blink", Aliases = { "b" }, @@ -12,11 +26,21 @@ return { local mouse = context.Executor:GetMouse() local character = context.Executor.Character - if not character then + if not (character and character:FindFirstChild("HumanoidRootPart")) then return "You don't have a character." end - character:MoveTo(mouse.Hit.p) + character:AddTag("RayBlacklist") + + local raycastParams = RaycastParams.new() + raycastParams.FilterType = Enum.RaycastFilterType.Exclude + raycastParams.FilterDescendantsInstances = CollectionService:GetTagged("RayBlacklist") + raycastParams.IgnoreWater = true + raycastParams.CollisionGroup = "Default" + + local raycastResult = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000, raycastParams) + + character:MoveTo(if raycastResult then raycastResult.Position else mouse.Hit.Position) return "Blinked!" end, diff --git a/Cmdr/BuiltInCommands/Debug/thru.lua b/Cmdr/BuiltInCommands/Debug/thru.lua index 3ed5658e..cb17b7bc 100644 --- a/Cmdr/BuiltInCommands/Debug/thru.lua +++ b/Cmdr/BuiltInCommands/Debug/thru.lua @@ -1,3 +1,17 @@ +local CollectionService = game:GetService("CollectionService") + +for _, instance in workspace:GetDescendants() do + if instance:IsA("BasePart") and not instance.CanCollide then + instance:AddTag("RayBlacklist") + end +end + +workspace.DescendantAdded:Connect(function(descendant) + if descendant:IsA("BasePart") and not descendant.CanCollide then + descendant:AddTag("RayBlacklist") + end +end) + return { Name = "thru", Aliases = { "t", "through" }, @@ -19,12 +33,22 @@ return { local mouse = context.Executor:GetMouse() local character = context.Executor.Character - if not character or not character:FindFirstChild("HumanoidRootPart") then + if not (character and character:FindFirstChild("HumanoidRootPart")) then return "You don't have a character." end + character:AddTag("RayBlacklist") + + local raycastParams = RaycastParams.new() + raycastParams.FilterType = Enum.RaycastFilterType.Exclude + raycastParams.FilterDescendantsInstances = CollectionService:GetTagged("RayBlacklist") + raycastParams.IgnoreWater = true + raycastParams.CollisionGroup = "Default" + + local raycastResult = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000, raycastParams) + local pos = character.HumanoidRootPart.Position - local diff = (mouse.Hit.p - pos) + local diff = ((if raycastResult then raycastResult.Position else mouse.Hit.Position) - pos) character:MoveTo((diff * 2) + (diff.unit * extra) + pos)