Vector3 Round, Ceil, and Floor

As a Roblox developer, it is currently too hard to perform rounding operations on Vector3s.

If Roblox is able to address this issue, it would improve my development experience because Vector3s would be easier to round. Also, because Luau supports 3-wide SIMD for Vector3, there would also be a performance benefit of being able to rely on native Vector3 operations as opposed to rebuilding Vector3s with rounded components.

Rounding today:

local vector = Vector3.new(2.4, 2.1, 2.3)
local roundedVector = Vector3.new(math.round(vector.X), math.round(vector.Y), math.round(vector.Z))

Rounding if this was implemented:

local vector = Vector3.new(2.4, 2.1, 2.3)
local roundedVector = vector:Round()

Example use cases for native rounding of Vector3s: Grid based Workspace to game coordinate conversion, terrain generation where data is stored in 2D or 3D data structures, and controlling set offsets for in game item placement. All of these use cases are possible today by doing rounding operations on the components of an existing Vector3 and creating a new one, but it would be nice if it was easier to denote the rounding operations. If there would be SIMD performance improvements for rounding Vector3s directly, it would be very beneficial for procedural generation applications.

31 Likes

What do you need it for? Might help to supply use cases so they can estimate how much it would be used and assign the right priority based on that.

4 Likes

Thanks for adding! I was thinking the same. If I were making a grid-based game I would probably want Roblox to provide a way to specify the cell size to round to though, otherwise I need to run my own code anyway if I want anything other than 1x1x1 grid.

6 Likes

Even in this situation, it would be cleaner to be able to divide my starting vector by my grid unit size, perform the round/ceil/floor on the vector directly, and then multiply by my grid unit size. Again, very possibly today, but the math is more expensive to perform on components individually and you end up with 3x more lines of code most of the time. Often this code ends up in helper functions I write for every project of this type but the need to write such helper functions every time I am doing these types of operations seems to hint it would be very useful to have them built in!

4 Likes

Also particularly useful when you need to tile stuff to fit a length, area or volume - being able to round numbers easily above 1D would help make much of this code a lot more concise and readable.

3 Likes