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

help with moving models in grids?

Asked by 8 years ago
player = game.Players.LocalPlayer
mouse = player:GetMouse()
m = Instance.new("Message",player.Character) -- making it visible only to the player
m.Name = 'short'
game.Workspace.Model.Parent = m
mouse.Move:connect(function()
    local x = math.floor(mouse.Hit.p.X) -- these make the grids
    local y = math.floor(mouse.Hit.p.Y)
    local z = math.floor(mouse.Hit.p.Z)
    player.Character.short:WaitForChild("Model"):SetPrimaryPartCFrame(CFrame.new(Vector3.new(x,y,z)+Vector3.new(0,.5,0)))
end)

The above script moves a model in a one stud grid, but how do i move it in a 2 or 3 or 4 or 5 or 6 or 7 or 8 or anything i want stud grid? Multiplying or dividing or adding or subtracting the mouse.Hit just makes the model move in weird way, and still only 1 stud. So, my question to you, is how the heck do you move models in a more than one stud grid?

and btw, for anybody who downvotes, would you please leave a reason on the comments?

1 answer

Log in to vote
1
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago

you would do this like this:

player = game.Players.LocalPlayer
mouse = player:GetMouse()
m = Instance.new("Message",player.Character)
m.Name = 'short'
game.Workspace.Model.Parent = m
mouse.Move:connect(function()
    local x = math.floor(mouse.Hit.p.X)
    local y = math.floor(mouse.Hit.p.Y)
    local z = math.floor(mouse.Hit.p.Z)
    if x % 2 == 1 then -- this is the part that does it, this checks if it needs to be changed
        x = x - 1 -- changes it
    end
if z % 2 == 1 then -- repeat for the z
        z=z - 1
    end
    player.Character.short:WaitForChild("Model"):SetPrimaryPartCFrame(CFrame.new(Vector3.new(x,y,z)+Vector3.new(0,.5,0)))
end)

this will add 1 onto the grid size, change the ones to 4 if you want the grid to be 5 studs, the number that is in the if's adds to the grid size.

Ad

Answer this question