Hey Devs! I’m kinda confused why do we have two ways to get the mouse position (2d) to the 3d space?
What would be the pros and cons and best uses for the two?
Hey Devs! I’m kinda confused why do we have two ways to get the mouse position (2d) to the 3d space?
What would be the pros and cons and best uses for the two?
Mouse.Hit
Provided Example Use:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
local targetPosition = mouse.Hit.p
print("Mouse hit position:", targetPosition)
end)
Provided Example Use:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
mouse.Button1Down:Connect(function()
local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y)
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
local hitPart, hitPosition = workspace:FindPartOnRay(ray, player.Character, false, true)
if hitPart then
print("Ray hit position:", hitPosition)
else
print("Ray did not hit anything")
end
end)
Choose Mouse.Hit
for simplicity and MouseRaycasting
for detailed and precise interactions.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.