Placement System Problems

I am writing a placement module where you can edit certain settings such as grid size, interpolation and others to make a custom placement system similar to another one I saw. It is supposed to be very simple to use, but there is one problem. The models sometimes don’t snap to a grid. The models don’t snap when:

  1. The model is a certain size (example 1x1x1, 2x2x1)
  2. The model is rotated while placing by using the rotate system.
  3. The grid size is set to anything but 2 studs.
  4. The plot is not a multiple of the grid size

Other times, the model snaps fine. Such as when all these things are in play at one time:

  1. The model is un-rotated
  2. The model’s primary part is the “correct” size (such as 4x4x4)
  3. The grid size is set to 2
  4. The plot is a multiple of the grid size

I am using the simple formula for snapping, but I find it does not work with most situations.

local function CalcGrid1(pos, grid)
    return math.floor((pos / grid) + 0.5) * grid
end

I tried using the models size to fix this, but it does not work when the model is rotated or grid size is changed.

local function CalcGrid2(x, grid, primary)
    posX = math.floor((x / grid) + 0.5) * grid + (primary.Size.X / grid)

    -- same for z
end

Here are some photos of the correct and incorrect snapping (using the second method).

Correct

Incorrect


(I tried to post a video, but it did not work)

The model rotates by 90 degrees.

I have looked at lots of other posts on placement systems, but have only found them using the first formula/method which seems to work fine for them.

Is there a simple way to fix this problem without having tons of math to deal with?

Thanks! :+1:

My only guess would be that you don’t take the model rotation into account, or maybe because you apply the rotation wrongly (same for size), but I might me wrong.

I suggest you to look at the source of this module and check how tunicus did it.


Maybe there you can find a way on how to calculate the proper position with rotation.

3 Likes

Are these grids only on the XZ plane or are you looking at supporting other planes as well? You have quite a large desired feature set but if done properly each feature can be developed independently.

1 Like

What you have here is a lack of offsetting.

A 1x2 blocks center point is .5,1 so that is point of rotation.
I would recommend tracking a corner and using it to match the grid points.

So you have an item.
Find upper left corner offset (top of view being -z dir)
xAxisSize/2 , 0, zAxisSize/2
Move to a corner
setCFrame to grid point + offset

Rotating 90degrees makes previous X your Z and Z, X
zAxisSize/2, 0, xAxisSize/2

If you want this and want to allow freedom of placement you will need to add the ability to change which corner is being used to snap.
So that you choose which corner of an object to connect to which corner of the grid. regardless of rotation.

1 Like

It only snaps and moves along XZ planes not Y.

I have looked at that before. It was too complicated for me.

Thanks! I have been able to fix the problem with “incorrect” model sizes using your reply. Now I won’t get people saying “Why is the module not working?” (I have a module that handles placement using the incorrect grid system).

Glad I could help, good luck. :slight_smile:

1 Like