How do you make an object follow your mouse on a grid?
Asked by
5 years ago Edited 5 years ago
I'm trying to get a part to follow my mouse on a grid, but it just feels... off...
It does not feel like I'm doing the grid part correctly. I tried using both math.ceil and math.floor;
01 | local camera = workspace.CurrentCamera; |
02 | local mouse = game.Players.LocalPlayer:GetMouse(); |
04 | local previewItem = Instance.new( "Part" ); |
05 | previewItem.Parent = game.Workspace; |
06 | previewItem.Size = Vector 3. new( 1 , 1 , 1 ); |
08 | mouse.Move:Connect( function () |
09 | local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y); |
10 | local ray = Ray.new(unitRay.Origin, unitRay.Direction * 500 ); |
12 | local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, { game.Players.LocalPlayer.Character, previewItem } ); |
15 | previewItem.Position = Vector 3. new(math.floor(pos.X / 5 ) * 5 , math.floor(pos.Y / 5 ) * 5 , math.floor(pos.Z / 5 ) * 5 ); |
What am I doing wrong and how should I be doing it?
It follows my mouse perfectly without the grid code, the grid code is causing the issue.