Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help with this math problem I have with my build system?

Asked by 4 years ago
Edited 4 years ago
    print(math.floor(Mouse.Hit.X / GridSize) * GridSize)
    print(math.floor(Mouse.Hit.X))

Let's say that mouse X is 50 and gridsize is 2. That means that the first one will do 50/2 = 25 * 2 = 50 Bottom one will be 50.

Same answer, yet, when I made a snap building system, it gives different results.

FULL SCRIPT:



local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local PosX local PosY local PosZ local Model = game.ReplicatedStorage.Crate:Clone() Model.Parent = workspace local GridSize = 5 local function snap() PosX = math.floor(Mouse.Hit.X / GridSize) * GridSize PosY = Model.PrimaryPart.Position.Y PosZ = math.floor(Mouse.Hit.Z / GridSize) * GridSize end local function Movement() --Mouse.TargetFilter = Model snap() Model:SetPrimaryPartCFrame(CFrame.new(PosX, PosY, PosZ)) end Mouse.Move:Connect(Movement)
0
I checked it on a basic part and it works for me. Just bear in mind that Position is in the MIDDLE of the part. sleazel 1287 — 4y

Answer this question