hello everyone, i am making a tycoon with placement system but i have a problem with the grid.
currently i am using: newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE) * CFrame.Angles(0,math.rad(ROT),0)
and then i tween the models primarypart to “newCFrame”
its works fine if the model that needs to be placed is the size of TILE wich is 3.5 studs.
but i want to be able to place walls with a difrent grid of 7 but it stil needs to be aligned to the grid of TILE,
since ive never been good at math i cant find a solution for this.
Hmm… looks like a snapping issue… I suggest you take a look at this article in ScriptingHelpers, particularly the section on snapping.
And if you’re looking to make a more advanced system which also saves items you place, this article is a good choice
Note that this article is more advanced and requires a moderate knowledge of Lua and OOP, so if you’re new to scripting I’d suggest you try the first to make a script from the first article and then gradually learn new features and move to the second one.
thnx for trying but this is not the problem i have
im using math.floor(mouse.Hit.Position / grid) * grid
but if i change the grid from 3.5 to 7 its not aligned with eachother to solve this i would have to change where the grid position starts 0,0,0 but idk how and in what way
okay so i found what to do. i dit this to calculate the grid position: newCframe = CFrame.new(math.floor(mouse.Hit.X / TILE +.5) * TILE + TILE/factor, math.floor(mouse.Hit.Y / 5 +.5) * 5, math.floor(mouse.Hit.Z / TILE +.5) * TILE + TILE/factor) * CFrame.Angles(0,math.rad(ROT),0)
but as soon as i wanted to place a model with a bigger primarypart that model went of grid.my solution was this: