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

Less mouse precision possible?

Asked by 7 years ago

So I have a ROBLOX Build Battle game, with my custom stamper tool. It works all good and well, but it is WAY too precise. It's about 1 stud precision, which is WAY too much! The code snippet (below) should help, but I want to know if it is possible to use LESS precision, SH was a last resource, because i've tried almost everything else.

[Snippet]:

round = function(num)
    return math.floor(num) -- Here is the function I would like to change
end
local sel = game.Lighting.SEL:Clone()
sel.Parent = game.Players.LocalPlayer.Character
m.Move:connect(function()
    if mode == "place" then
    sel.Box.Transparency = 0
    sel.Position = Vector3.new(0,2.25,0) + Vector3.new(round(m.Hit.X),round(m.Hit.Y),round(m.Hit.Z))
    print(sel.Position) 
    elseif mode == "delete" then
    if m.Target.ClassName == "Part" and m.Target.Name == "Part" and not m.Target.Locked then
    script.Parent.Selector.Adornee = m.Target
    script.Parent.Selector.TargetSurface = m.TargetSurface
    sel.Box.Transparency = 1
    elseif mode == "select" then
    if m.Target.ClassName == "Part" and m.Target.Name == "Part" and not m.Target.Locked then
    script.Parent.Selector.Adornee = m.Target
    sel.Box.Transparency = 1
    end
    end
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The way to round with a different precision is to divide by the factor you want when you plug it in, and then multiply it when it comes out of the function. I don't know the best way to explain this math trick.

One thing we will want to do is add half the factor so that it does not floor each time (floor versus ceil ) We basically do this so that rounding is done at exactly the halfway point (instead of rounding down - floor, or rounding up - ceil each time).

round = function(num, factor)
    return math.floor((num + factor / 2) / factor) * factor -- Here is the function I would like to change
end

For example, if I want to round to the nearest 2 studs ...

round(1.25, 2)

2

0
Thanks! I'll try this out, if it works I'll accept this answer. SebbyTheGODKid 198 — 7y
Ad

Answer this question