TLDR: How can i trick my game into assuming a different origin with a cframe?
I’m almost there!!
I am working on a placement system, and the snap to grid is the last thing to do. Right now, my placement system has no snap to grid yet, but I have the steps to get there.
I already have a snapping function,
local function round(n: number): number
return math.floor(n / 3 + .5) * 3
end
but how can I make that work with this custom set grid-origin which is rotated differently and at a different position other than 0,0,0?
Key Red part: ray hit + ray normal
By that, here is a grid that is generated based off of the face the mouse is on. Its position does not change no matter where my mouse is on a specific face.
How can I get snap-to-grid to lock on this specific custom set origin I made? I tried using :ToObjectSpace() with the cframe of my grid before applying the snap function to the position, but it didn’t work. I also tried dividing the cframe of the block by the grid cframe before snapping (and then re-multiplying afterwards). Can anyone help me out?
Also when I say divide cframe, I mean cframe1 * cframe2:Inverse()