My utility module (bunch of functions I use more or less often)

Decided to make it public. Read through if theres anything you find useful. Some things are old and I dont know if they work, but most of it should be fine.
Myself I mostly just use the ‘clamp’ function, even though thats pretty trivial.

If you have formed an utility module yourself, do share, Id like to see if I can expand mine in any way.

Its just a long table of functions (I should change the internal organization so its not a list, but just separate functions, doesnt affect usage of the module tho).

Contains:

  • Number operations (clamping, interpolation, getting sign, smoothstep, find 0-1 alpha ‘position’ of number within arbitrary interval…)
  • Vector operations (getting random vector, interpolation, slerping, finding best axis-aligned direction, angle between vectors, summing components, multiplying components, projecting, getting sign of each component…)
  • Object hierarchy stuff (scan with callback, scan with callback ignoring root, find parent model)
  • Multi-segment raycasting (for the cases when you need more complex logic for deciding at what part to stop raycasting)
  • Some physics stuff (find velocity at point, get center of mass, get force/torque from impulse…)
  • Weld/joint stuff (short syntax to create weld/motor, find external joints of model, find internal joints of model, with data structure/map to speed up joint lookup which can get slow otherwise, interpolate weld C0/C1)
  • Part cutter function (separate box-shaped core from a regular brick, leaving the core and the surrounding remaining parts). Decided to throw it in the util module because I use it a lot.
  • Triangle creator function (2 wedges). I dont use this one really but it should work.
  • Calculate model extents / center, using a primary part for orientation (assumes box shaped parts).
  • Child filter object (listens for added children of instance, maintains table of them) with filter callback. To avoid having to iterate over all the children.
  • Rate limiter object (set rate, and how much it can ‘accumulate’ if you dont use up the rate). If you want to do something at a specific rate (like how roblox might rate-limit datastore calls), which is annoying to code if your rate doesnt exactly match what wait() can do.
  • timedLoop function for fading/interpolating over given duration of time
  • alignToClosestOrientation function to ‘snap’ a CFrame so its at right angles with another given cframe (I need it to ‘dock’ a flying thing onto a docking thing). Has some limited constraining abilities to exclude orientations.
  • weightedRandomPick object (self explanatory)
  • count function (count number of keys in table), and find function (just iterates until it finds given value)
  • getColorBrightness function (no, just averaging rgb isnt how it works)
  • custom event object (works kinda similar to roblox events), only used it once though.
  • findoverlap function (finds area of intersection of 2 2D AABB given)

I think thats most of it.
I tried to add comments to explain how they work, but some things you just have to read the function body. Dont assume everything is 100% tested either. Only tested as far as I needed them to work.

3 Likes