Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Movin Block Like In A Grid Can Someone Help me?

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:


  --Intilaze Player's Mouse
  local playerMouse = game.Players.LocalPlayer:GetMouse()
  local pos = 0
 

  --Tool Equipped
script.Parent.Equipped:Connect(function(build)
	--Mouse Down Event
	build.Button1Down:Connect(function()
		
		print(playerMouse.hit.p)
	
		
	    local cwb = game.Workspace.WoodBlock:Clone()
	    
	    cwb.Parent = game.Workspace

		
		  
		
		 cwb.Position = playerMouse.hit.p
		 cwb.CFrame = cwb.CFrame + Vector3.new(0,4,0)
	
	   
	 
	    
		
	end)
	
	
	
	
end)

1 comment

0

It's called a dragger man

1 answer

✓ Accepted answer

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

local Gridsize = 6
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

Grid.Position.Y + .1

My Grid Sytem

2 comments

0

Thanks!

0

And I fixed my Issue about placing blocks with Ray Operation with your snapping formula :)

This discussion is preserved as it was. New answers, comments, and votes are closed.