'How do i get the mouse position to a part in roblox?
I truly want to know. How do i get the mouse position to a part in roblox? Like, i want to get the mouse position, on screen, aligned with a part. Let's say the part position is 10,10,10 and i want my mouse to point at that exact position, how can i do that? (I just need to get the position, ex: 1093x899, 1789x305. Didn't understand? Here, i simply want to know the position, on which my mouse would say that there is the 'part' that i want my mouse to point at. Any help is nice!
Solution 1:[1]
Take a look at the docs for Camera:WorldToScreenPoint.
I've adapted the code sample from there:
local camera = workspace.CurrentCamera
-- get the position of the part you care about
local targetPart = game.Workspace.YOUR_PART_NAME
local worldPoint = targetPart.Position
-- get the screen coordinates
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
if onScreen then
local screenPoint = Vector2.new(vector.X, vector.Y)
print(screenPoint)
else
print("the part isn't on your screen right now")
end
You'll need to hook this up to a loop of some kind to repeated get the coordinates.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kylaaa |
