I made a build tool for my game, But I tried to moving stud to stud. (When I click some here,I want to part move like to colliding to 4 stud grid.)
Here's Code:
01 | --Intilaze Player's Mouse |
02 | local playerMouse = game.Players.LocalPlayer:GetMouse() |
03 | local pos = 0 |
04 |
05 |
06 | --Tool Equipped |
07 | script.Parent.Equipped:Connect( function (build) |
08 | --Mouse Down Event |
09 | build.Button 1 Down:Connect( function () |
10 |
11 | print (playerMouse.hit.p) |
12 |
13 |
14 | local cwb = game.Workspace.WoodBlock:Clone() |
15 |
Well its actually more complicated you would have to use math.floor
im actually attempting something like this myself and ive spent 4 days on it already its part of my game
So the snapping would be like
1 | local Gridsize = 6 |
2 | Marker.CFrame = CFrame.new((math.floor(mouse.Hit.X / GridSize +. 5 ) * GridSize), Grid.Position.Y + . 1 , (math.floor(mouse.Hit.Z / GridSize ) * GridSize)) |
In my case i was making a floor for the grid system so i did
1 | Grid.Position.Y + . 1 |