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

How could I accomplish a placement system with grid size over 1x1?

Here's kind of what I'm looking to do:

Twitter Gif Link Thing

I know I can use:

math.floor() and math.ceil() to round up and down. I also know I can create a rounding function:

local function round(number)
	return math.floor(number + 0.5) -- Rounds to the nearest whole number
end

I would like to know how I could accomplish this with a grid size over 1x1. Thanks!

3 comments

0

There are two options. You could either have it detect the mouse position which would check the nearest place for a tile, or you could have tiles and use mouse.Target.

0

Divide mouse pos by grid, add 0.5, round, and mutiply by grid (after rounding).

0

Made an answer even though this is a year old. LOL

1 answer

✓ Accepted answer

Simple solution!

***Divide mouse position by grid, add 0.5, round either up or down, and mutiply by grid (after rounding)**. You should be using a LocalScript for this.

Example:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Part= workspace.Part

local PosX, PosY, PosZ -- We will set these later

local function Round(GridSize)
	PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize -- Snaps
	PosY = 0.5
	PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize -- Snaps
end

local function Movement()
	mouse.TargetFilter = Part -- Ignores the model

	Round(2) -- Pass your grid size as an argument

	Part.Position = Vector3.new(PosX, PosY, PosZ) -- Positions
end

mouse.Move:Connect(Movement)

I KNOW I know that this is a year old but I just had to answer this. Hope this helps... if you see this.

1 comment

0

I accepted your answer a year later :) I hope you know I eventually did create an extremely smooth grid system soon after asking this question

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