The code below is meant to return a position in 3D space, endPosition. It usually does return a position in 3D space, however it is never on target, and when I test it out, it looks as if it has been hashed into some random position.
local mouseLocation = UIS:GetMouseLocation()
local unitRay = camera:ScreenPointToRay(mouseLocation.X, mouseLocation.Y)
local raycast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 2000, params)
local endPosition = raycast.Position
Is there anything wrong with my code that could cause this to happen? There are no errors, only a very incorrect endPosition.
This works well! I was trying to avoid using GetMouse, as Roblox has been talking about how they highly recommend to use User Input Service on their documentation instead, but this works way better! Thanks!