How do i make drag system like work at a pizza place?

I am having troubles making a drag system similar to work a pizza place or roblox studios
even using the drag detectors and shape casts
i cannot get half the result i want

--in the script
local object = script.Parent
local dragDetector = object.DragDetector
local raycast = require(script.Raycast) --object follows where mouse is
local constraint = require(script.Constraint) --limit object position to a radius

local radius = 25

dragDetector:SetDragStyleFunction(function(cursorRay)
	return raycast(cursorRay, dragDetector, object) --this sets the object position
end)

dragDetector:AddConstraintFunction(1, function(proposedMotion) 
	return constraint(proposedMotion, dragDetector, radius)
end)
--inside of raycast module
return function(cursorRay, dragDetector, object)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {object} -- Ignore the player’s character
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	local raycastResult = workspace:Raycast(cursorRay.Origin, cursorRay.Direction, raycastParams)
	local hitPosition = raycastResult.Position
	return CFrame.new(hitPosition)
end
--i do not know how to do the constraint to limit by the radius

I would like to make a custom response style for the drag detector of a mix of the smoothness of physics and the rigidness of geometric

raycasts work by hitting an object and sending the position where it hits
but when setting the pizza to that position it is half way in the wall
image

there’s a hacky solution that uses the normals to displace the pizza

	local offset
	if math.abs(hitNormal.Y) < 0.5 then
		-- Wall detected → Offset away from the wall based on its normal
		offset = hitNormal * pizzaRadius
	else
		-- Floor or ceiling detected → Offset along the normal
		offset = hitNormal * pizzaHeight
	end
	return CFrame.new(hitPosition+offset) * CFrame.Angles(0,0,math.rad(90))

however it does not work against walls that are rotated
image

so i thought about using shapecasts, however they have their own set of problems
image
the square is rotated based on the origin of the raycast, and i need it not be rotated on the world position.

not only that but the shapecast you can somehow get them to go through the floor and that is not a unreliability that i want

1 Like

If you try out Work At A Pizza Place, they use a grid based system to move the pizzas around. I believe they just use Mouse.Hit.Position and round that to a grid. You can then use WorldRoot | Documentation - Roblox Creator Hub to see if it’s a valid position. You might want to round the normal to world axes, multiply it by the size of the object in that axis, and then add that to the hit position. If you need some help implementing this, let me know.

1 Like

yeah i noticed that when playing the game to see how it works but i want to change things up to make it smooth rather than a grid system

Give me about an hour to finish some physics homework and I’ll cook something up for you. I think combining the normal with the Mouse.Hit.Position and GetPartBoundsInBox would be sufficient.

1 Like


Ended up just borrowing some code I wrote a while ago for an item spawning system. You can try the uncopylocked place here: Pizza Dragging - Roblox. You had mentioned one of the methods didn’t work on walls; not sure if you want them to rotate against walls or just be kept flat against them. You can toggle that Flattened variable to control it. You can see the two options here:


2 Likes

thanks for your help but i manage to get the block cast to work

game:GetService("RunService").Heartbeat:Connect(function()
	local lookVector = Part.CFrame.LookVector
	local cframe = CFrame.new(Part.Position) --resets part cframe
	--local cframe = Part.CFrame --orientated based on parts look vector
	local Result = workspace:Blockcast(cframe,Part.Size,lookVector * distance, NewParams)
	if Result then
		PartClone.Position = Part.Position + Part.CFrame.LookVector * Result.Distance
		--PartClone.Orientation = Part.Orientation
	end
end)

block.rbxl (67.5 KB)
pizza.rbxm (6.1 KB)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.