I am attempting to use Ray Casting for the first time and I feel like i'm missing something simple. Attached is my current code. At the moment the part returned is nil and the position does not seem to be correct. If anyone could give me a link or pointer that would be great! Thanks.
player = game.Players.LocalPlayer mouse = player:GetMouse() function camTurn() local camRay = mouse.UnitRay basePart, location = workspace:FindPartOnRay (camRay) print (basePart .. " Is touched here: "..location) end RunService:BindToRenderStep("CamTurn",500,camTurn)--I have tried lower priority as well
Your code doesn't work because rays require some length for hit detection but UnitRay
is only of length 1. (Unit).
However I do not recommend Lua raycasting every render frame, plus for no reason. You can simply use mouse.Target / mouse.Hit.