My instance-moving system is jittery for some reason... please help

I’m making a creator mode for a game called ‘Find The Boi’ (a puzzle game that isn’t fully done tbh), and I have a an instance-moving function that uses mouse.Hit.Position but it’s jittery and sometimes moves parts unintentionally

Here’s some footage of what’s happening:


here’s the function for moving a part

function ControlBuilder.PositionInstance(director: BasePart)
	if not selectedTarget then return end

	local dirData = directions[director.Name]
	if not dirData then return end

    -- setting up the director's position directly :p
	local mousePos = mouse.Hit.Position
	local basePos = director.Position

	local targetPos = Vector3.new(
		if dirData.sideAxis == "X" then mousePos.X else director.Position.X,
		if dirData.sideAxis == "Y" then mousePos.Y else director.Position.Y,
		if dirData.sideAxis == "Z" then mousePos.Z else director.Position.Z
	)
	
	director.Position = targetPos
	
    -- calculating offset of other directors and the selected instance
	local offsetAmount = (selectedTarget.Size[dirData.sideAxis] / 2) + OFFSET_FROM_OBJECT
	local newSelectedPos = director.Position - (dirData.vector * offsetAmount)

	selectedTarget.Position = newSelectedPos 

	for _, child in selectedTarget:GetChildren() do
		if child:IsA("BasePart") and child:GetAttribute("IsPositioner") and child ~= director then
			local childDirData = directions[child.Name]
			if not childDirData then continue end

			local childOffset = childDirData.vector * ((selectedTarget.Size[childDirData.sideAxis] / 2) + OFFSET_FROM_OBJECT) 
			child.Position = selectedTarget.Position + childOffset
		end
	end
	
end

dirData stores the vector to move to and the sideAxis as a string
For example: a “Top” director has dirData = {vector = Vector3.new(0,1,0), sideAxis = "Y"})

This function is called when the player holds on one of the sides using UserInputService (via InputBegan and InputEnded). It gets looped through RenderStepped until the player releases the said side

I have tried using raycasting before, but I feel that it’s inefficient for this system, and it barely works. I might’ve set it up incorrectly though.

Are there any ways I can reduce jitter and accidental drags? Thanks :happy3:

→ I’m not that active here so I might respond late

1 Like

Solved: Issue is that I’ve been relying on mouse.Hit which gets the collision between the mouse ray and a basepart [or any physical instance]

Instead of using said method, I cast a ray from the camera with the 2D mouse position via camera:ScreenPointToRay(mouse.X, mouse.Y) and used that to solve for the intersection point between the mouse ray and the drag plane. With that, I can project the mouse movement onto the selected axis (X/Y/Z) while using vector dot product to get the signed movement amount along the axis.

All of this is inspired by F3X Btools moving instance feature or whatever you call it ;p

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