Introduction
Hello, I’ve seen a lot of cool creations that involved using triangle grids, so I’ve decided to create a module so that you can create them with ease!
(Credit to EgoMoose for the triangle function)
Here’s the link: GridModule - Roblox
cool demo
(note that you can make a lot more stuff than this with the module, such as triangle terrain generation or audio visualizers)
How do I use it?
Disclaimer: You need to have a solid understanding of multidimensional arrays to use this.
First off, let’s require the module.
local gridModule = require(PATH_TO_GRID_MODULE) -- Replace PATH_TO_GRID_MODULE with where it is in your game!
Great! Now we are able to use all of the module’s functions.
Let’s look at the most important function first, InitializeGrid. This function is pretty self explanatory(it initializes the grid). It takes in a width, a height, and a cell size(distance between each point on the grid). Let’s just add it in:
local gridModule = require(PATH_TO_GRID_MODULE)
gridModule.InitializeGrid(10, 10, 4)
Now let’s go into play mode, and observe what happens:
Cool! We now have a grid. To distinguish between all the wedges, I have added a property to the module called DebugColors
. It just randomizes the wedge colors.
local gridModule = require(PATH_TO_GRID_MODULE)
gridModule.DebugColors = true -- Always remember to set DebugColors before InitializeGrid!
gridModule.InitializeGrid(10, 10, 4)
It’s still a bit boring, the grid is pretty static. We want to make these move!
So let’s create a multidimensional array and set each coordinate to a Vector3:
local gridModule = require(script.Parent)
gridModule.DebugColors = true
gridModule.InitializeGrid(10, 10, 4)
local points = {}
local RNG = Random.new()
for y = 1, 10, 1 do -- This creates a multidimensional array.
points[y] = {}
for x = 1, 10, 1 do
points[y][x] = Vector3.new(x*4,RNG:NextNumber(0, 5),y*4) -- Set the Y to a random number, multiply the X and Z by the distance between each point.
end
end
gridModule.ModifyPoints(points)
Woah! All the points are now random and it looks pretty cool. Now you can modify the script to make your own cool triangle grids!
By the way, calling ModifyPoints
every frame won’t lag since this module reuses the wedges(Creating new wedges every frame would cause a ton of lag).
Fin
Thanks for reading!
I hope you like this module, and I can’t wait to see what you’ll make with it. Feedback is also appreciated.