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

How is this possible?

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.

1 answer

✓ Accepted answer

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.

2 comments

0

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

0

I forgot to multiply by the gridsize again, my bad.  Should work now

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