What do you want to achieve? Keep it simple and clear!
I want to fix the dragdetector part so that it stops moving on the Y axis completely
What is the issue? Include screenshots / videos if possible!
Notice how the dragdetector part is moving on the Y axis irregularly
here is my custom ResponseStyle
local guide = workspace.PlacementGuide
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local box = guide.Frame.Box
local cursor = guide.Cursor
local cursorPos = cursor:GetBoundingBox().p.Y
local boxPos = box.Position
local function checkIfIn(pos)
local part = Instance.new('Part')
part.Size = Vector3.new(0.1,20,0.1)
part.Transparency = 1
part.Anchored = true
part.Parent = workspace
part.Position = pos
for _, instance in part:GetTouchingParts() do
if instance == box then
return true
end
end
return false
end
cursor.Cursor.DragDetector.DragContinue:Connect(function()
local mouse = player:GetMouse()
local mouseRay = camera:ScreenPointToRay(mouse.X, mouse.Y)
local pos = workspace:Raycast(mouseRay.Origin, mouseRay.Direction)
if pos then
if checkIfIn(pos.Position) then
cursor:MoveTo(Vector3.new(pos.Position.X, 2, pos.Position.Z))
else
local look = CFrame.new(Vector3.new(pos.Position.X, boxPos.Y, pos.Position.Z), boxPos)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {box}
local raycast = workspace:Raycast(look.Position, look.LookVector, params)
if raycast then
cursor:MoveTo(Vector3.new(raycast.Position.X, 2, raycast.Position.Z))
end
end
end
end)
I can send the rbxm file too, as it might have to do with the model itself but I don’t think so
Nevermind, i just realized it’s because I didn’t destroy the part after checking. I also added new params to only include the drag limit and the baseplate
Fixed code down here
local guide = workspace.PlacementGuide
local guidePos = guide:GetBoundingBox().p
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local box = guide.Frame.Box
local cursor = guide.Cursor
local cursorPos = cursor:GetBoundingBox().p.Y
local boxPos = box.Position
local function checkIfIn(pos)
local part = Instance.new('Part')
part.Size = Vector3.new(0.1,20,0.1)
part.Transparency = 1
part.Anchored = true
part.Parent = workspace
part.Position = pos
local touchingParts = part:GetTouchingParts()
part:Destroy()
for _, instance in touchingParts do
if instance == box then
return true
end
end
return false
end
cursor.Cursor.DragDetector.DragContinue:Connect(function()
local mouse = player:GetMouse()
local mouseRay = camera:ScreenPointToRay(mouse.X, mouse.Y)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {box, workspace.Baseplate}
local pos = workspace:Raycast(mouseRay.Origin, mouseRay.Direction*1000, params)
if pos then
if checkIfIn(pos.Position) then
cursor:MoveTo(Vector3.new(pos.Position.X, 2, pos.Position.Z))
else
local look = CFrame.new(Vector3.new(pos.Position.X, boxPos.Y, pos.Position.Z), boxPos)
local raycast = workspace:Raycast(look.Position, look.LookVector*1000)
if raycast then
cursor:MoveTo(Vector3.new(raycast.Position.X, 2, raycast.Position.Z))
end
end
end
end)
cursor.Cursor.DragDetector.DragEnd:Connect(function()
cursor:MoveTo(Vector3.new(guidePos.X, 2, guidePos.Z))
end)