Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How does Handle dragging work? (mouse movement to 3D coordinates)

Asked by
Tesouro 407 Moderation Voter
7 years ago
Edited 7 years ago

I'm working on a part placement tool, like many building games have. Moving the object through X and Z axis is fine, as long as there is some baseplate to be detected by mouse.Hit.

When it comes to Y axis, I wanted to make a system that locks the object position in X and Z, so I can control its height (like RCT building controls, if anyone remembers those).

The problem is that I don't know how to transform mouse movement into precise 3D coordinates. The closest thing that works like that is the dragging system of Handles, but I don't want to use them. Instead, I'd like to know how do they work, so I can make my own. Does anyone know how they work? Is it built-in or it uses regular Roblox API?

1 answer

Log in to vote
0
Answered by 7 years ago
--local script
local player=game.Players.LocalPlayer
local mouse=player:GetMouse()
local runservice=game:GetService("RunService")
local p=workspace.Part --example
mouse.TargetFilter=p

runservice.RenderStepped:Connect(function()
       p.Position=mouse.Hit.p
end)
Ad

Answer this question