Mouse position issue with draggable objects

hello!! in my game you can drag objects with ur mouse. so, as a failsafe for dragging stuff into the void, i added a limit to how far it can go

the issue is that the part is being moved like half the actual mouse distance for some reason. please help!

local function updateDrag()
	local sizeAdjustment = Vector3.FromNormalId(mouse.TargetSurface) * (currentHoveredObject.Size / 2)
	local newPosition = mouse.Hit.Position + sizeAdjustment

	currentHoveredObject.Position = newPosition

	local distanceFromCamera = newPosition - mouse.Origin.Position

	if distanceFromCamera.Magnitude > MAX_DRAG_DISTANCE then
		currentHoveredObject.Position = mouse.Hit.LookVector * MAX_DRAG_DISTANCE
	end
end

im so stupid. just use rays

local function updateDrag()
	local sizeAdjustment = Vector3.FromNormalId(mouse.TargetSurface) * (currentHoveredObject.Size / 2)
	local newPosition = mouse.Hit.Position + sizeAdjustment

	currentHoveredObject.Position = newPosition

	local distanceFromCamera = newPosition - mouse.Origin.Position

	if distanceFromCamera.Magnitude > MAX_DRAG_DISTANCE then
		local ray = camera:ScreenPointToRay(mouse.X, mouse.Y, MAX_DRAG_DISTANCE)

		currentHoveredObject.Position = ray.Origin + ray.Direction
	end
end

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