I’m trying to get the mouse position of the player located to its reverse position depending on the Humanoid Root Part position. I know I will have to use ToObjectSpace()but I don’t know how and in which way.
Honestly there is only 1 issue with this, when the left side is not as high as the right side.
Instead I suggest to get the screen size, get the mouse position and then raycast from there.
Another issue is that it will get a floating point in any position, due to the y-offset.
The screensize can be gotten via CurrentCamera.ViewportSize, this returns a Vector2.
The mouse screen position can be gotten via mouse.x and mouse.y
Now to finally raycast you can use the reverse mouse position use camera:ViewportPointToRay()
For anyone who would want to do this more accurately I suggest to do the following:
local mouse = LocalPlayer:GetMouse()
local camera = workspace.CurrentCamera
local size = camera.ViewportSize
-- Raycast outward:
local ray = camera:ViewportPointToRay(size.X - mouse.x, size.Y - vector.Y, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {partToCheck, game.Players.LocalPlayer.Character}
local raycastResult = workspace:Raycast(ray.Origin, ray.Direction * 1000, raycastParams)