You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like to find out how to make a part’s Y axis the same as the level of my mouse’s Y axis but in world space.
What is the issue? Include screenshots / videos if possible!
I can’t figure out how to find the 3d Y Point that is equivalent to my 2d Y Mouse location.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to use Mouse.Hit.p but since that just returns the intersection between the mouse’s internal ray with an object in the space it produces inaccurate results.
Here’s a video of how the inaccurate results looked:
Here’s the code with Mouse.Hit.p
local part = workspace.MovePart
local userInputService = game:GetService("UserInputService")
local Mouse = game.Players.LocalPlayer:GetMouse()
userInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
local hitp = Mouse.Hit.p
part.Position = Vector3.new(part.Position.X, hitp.Y, part.Position.Z)
end
end)
Try using this, it worked fine for me. It’s not much of a difference, but there’s no issue for me. (I created a setup similar to yours)
local part = workspace.MovePart
local userInputService = game:GetService("UserInputService")
local Mouse = game.Players.LocalPlayer:GetMouse()
userInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and Mouse.Target ~= nil then
local hitp = Mouse.Hit.Position.Y
part.Position = Vector3.new(part.Position.X, hitp, part.Position.Z)
end
end)
This sort of works but only when there’s walls behind it, the ideal goal is to have the height of the part be the same as the height of the mouse at all times.
local rayOrigin = ----current camera position
local rayDirection = ---mouse hit position + vector3.new(range,range,range)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)