of     1   

Abandion
#228143574Monday, November 27, 2017 1:19 PM GMT

I wanted to round all numbers in a vector3 value to the nearest multiple of 3, or if that's not possible, to the nearest whole. Is there a way to do this? if there is a finite amount of matter in the universe, how does Olive Garden offer unlimited breadsticks?
Luo_Basics
#228143610Monday, November 27, 2017 1:20 PM GMT

yea math.floor(num + 0.5) will round to nearest multiple of 1, so it wont be hard to find out nearest multiple of 3, considering math.floor(num*2 + 0.5)/2 would be 0.5, anyway i have to go good luck.
Abandion
#228143664Monday, November 27, 2017 1:23 PM GMT

thanks if there is a finite amount of matter in the universe, how does Olive Garden offer unlimited breadsticks?
Chrounum
#228143686Monday, November 27, 2017 1:24 PM GMT

tracking this thread. #code print("don't forget to dry the towel after use")
128Gigabytes
#228146420Monday, November 27, 2017 3:28 PM GMT

It would actually be reverse dividing and multiplying order of what Luo said. math.floor((x / 3) + 0.5) * 3
crazyman32
#228146510Monday, November 27, 2017 3:33 PM GMT

The way to round to the nearest 'x' number is to use the following algorithm, where 'number' is the original number, and 'multiple' is the number being rounded toward (e.g. 3): floor( number + (multiple * 0.5) / multiple ) * multiple As Lua code in the form of a function, it could look like this: function RoundMultiple(n, mult) return math.floor((n + (mult * 0.5)) / mult) * mult end To do this with a Vector3, we just need to write another function that calls 'RoundMultiple' for each X, Y, and Z property of a Vector3. Thus, to answer your question, a finalized function might look like this: function RoundVector3(v3, mult) local x = RoundMultiple(v3.X, mult) local y = RoundMultiple(v3.Y, mult) local z = RoundMultiple(v3.Z, mult) return Vector3.new(x, y, z) end And you could call it like this: local v3 = Vector3.new(30, 23, 21) local v3Rounded = RoundVector3(v3, 3) -- Round all the values to the nearest multiple of '3'
128Gigabytes
#228146611Monday, November 27, 2017 3:38 PM GMT

Crazyman32 why would you use that algorithm for rounding to a multiple instead of mine? Both get the same results but yours has to do more mathematical functions, granted, not much more.
tbnj123
#228146700Monday, November 27, 2017 3:42 PM GMT

Scale = 3 num = 4 num = num+Scale/2 final = num-num%Scale does this count..?
crazyman32
#228146790Monday, November 27, 2017 3:46 PM GMT

@128Gigabytes - You're correct that yours will work better. I just grabbed mine from really old code that I had. Definitely preferable to have less operations.
IcedVapour
#228148962Monday, November 27, 2017 5:02 PM GMT

math.floor((number / 3) + 0.5) * 3
IcedVapour
#228149002Monday, November 27, 2017 5:04 PM GMT

nvm someone already posted it
Luo_Basics
#228163707Monday, November 27, 2017 11:02 PM GMT

"nvm someone already posted it" hmm thats odd considering your script was same as 128gb except "x" was replaced with "number"

    of     1