How to make a object dragable in viewport frame

hi everyone, I was making a game and want to incorporate this feature of an object moveable in a viewport frame. I have an example in phantom forces (also in the video) of it. any help on making this because I don’t know how to make this. thanks

1 Like

You need to start learning Mouse | Documentation - Roblox Creator Hub, then Mouse | Documentation - Roblox Creator Hub to know how to intercept the mouse position in the 3D space.
After, learn CFrames | Documentation - Roblox Creator Hub to understand how to move the object in the 3D space.

1 Like

I made a topic a while back about a similar problem. Maybe it can help you?

1 Like

I do not recommend this due to the staff saying how Mouse is a legacy feature and is going to be deprecated soon.

Instead, use UserInputService or ContextActionService. Whichever one fits your needs.

Great. What’s the replacement for Mouse.Hit?

Here is a source:

And here’s an example of how I did it based on the source:

-- InputChanged because the mouse is constantly going to be in movement, hence the conditional statement on the second line
UIS.InputChanged:Connect(function(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local mouse_location = UIS:GetMouseLocation()
		local unscaled_ray = camera:ViewportPointToRay(mouse_location.X, mouse_location.Y - 36)
		
		local result = workspace:Raycast(unscaled_ray.Origin, unscaled_ray.Direction*1000)
		
		local target
		if result then
			target = result.Instance
			-- Making sure your Client is alive and existent
			if player ~= nil then
				if player.Character:FindFirstChild("Humanoid").Health > 0 then
					if target:IsA("BasePart") and target.Material == "Wood" then
                        --Make Gui do stuff by digging into the PlayerGui
                    end
				end
			end
		end
	end
end)

I haven’t analyzed it in detail, but I see no reason to use dozens of lines trying to get the mouse position in 3D space if I have it all done in just one command: mouse.Hit.

1 Like

Defining the Mouse is no longer going to be supported soon.

The Roblox staff has been very direct and has been encouraging everybody to utilize UserInputService. In fact, on the very top of the documentation page, it says:

Mouse has been superseded by UserInputService and ContextActionService , which cover a broader scope, are more feature rich, and support cross-platform patterns better. It remains supported because of its widespread use, but you should strongly consider using these alternatives.

You are still more than welcome to keep using Mouse and Mouse.Hit as you wish, but just keep in mind that this pathway is going to be unsupported very soon. They have been hinting this for a while now.

1 Like