How can you make a block move in increments relative to the mouse's position? (i.e. Miner's Haven)
This is not a request I just genuinely don't know where to start with this, please link wiki stuff, I can't find anything.
How can you make a block move in increments relative to the mouse's position? (i.e. Miner's Haven)
This is not a request I just genuinely don't know where to start with this, please link wiki stuff, I can't find anything.
You can use the Hit property of PlayerMouse (returned from method GetMouse) to get the position in the world.
But you don't want the part to be positioned at that point, but rather a point on the grid about equal to that point. You can do this by rounding the positon to the nearest multiple of the grid size.
Assuming mouse is defined:
local gridSize = 4
local part = game.Workspace.Part
mouse.Move:connect(function()
local position = mouse.Hit.p
position = Vector3.new(math.floor(position.X/gridSize), math.floor(position.Y/gridSize), math.floor(position.Z/gridSize))*gridSize
part.Position = position + Vector3.new(0, part.Size/2, 0)
end)
There are other ways to do this rounding that you may like better (e.g. n - n%gridSize), and that is perfectly fine too.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
when I try to change the gridSize it doesn't change the increment? how can I make this move by like 3 studs and not just 1
I forgot to multiply by the gridsize again, my bad. Should work now