Issue with placement system using normal vector

Hello, fellow scripters. I’m making this topic, because I am stuck with a current issue.
I’m working on a grid based - block building system but it’s not working as it should. I am currently using raycasting and normal vectors to detect which surface your mouse is on. This works perfectly fine for some of the axises, but for some reason it offsets way to much on other.

Sorry if i mispronounced some stuff.

1 Like

I can see you have made it so the block doesnt interfear with your mouse thats good.
If your going on a grid system id round your mouses position to the nearest increment you are using, e.g to nearest 4. Make sure this means you wont need to offset and it will appear to snap to the nearest grid point

1 Like

I’m sorry but I didnt quite understand what you meant.You suggest me to round the CFrame of where the block should be placed closer to the mouse?

1 Like

basically just round it. Theres no need for it to be far from the mouse
the reason why its doing that is because your adding a CFrame to it creating a gap.

if the mouse moves and you have rounded it, it will go to the closest grid point.

So if there is a block and you click the side of it and your blocks and grid are set to 4
you are clicking on the side of the block so it will be closer to where you want it and wont make blocks inside blocks

1 Like

Thanks alot for taking your time. This is the current way I’m approaching it on the server. I’m rounding the X,Y,Z axis with a gridsize of 3. Where exactly should it be rounded again? Sorry if I misunderstood you.

Should I do something different instead of adding on the normal vector?

1 Like

Forgot to mention. sizemodel is the size of the block being placed.

1 Like

It should round to half the size of your blocks.
Because when setting position the middle of the block is placed, so you might need to take that into acount.

Im not 100% sure because I cant test it right now and i need coffee.

it will either be the same size or half, either way its not complicated to change :slight_smile:

I don’t think that’s the issue though, because I’m multiplying it by the normal vector.

This is what happened when I took half of the size of the model.

Try adding .5 …

math.floor( ( Position.X / GridSize ) + 0.5 ) * GridSize--# example

Edit: Replied to the wrong person, sorry

adding a small number to get it into the correct grid reference seems like a good idea.
although if its in the negatives and your on the side of a cube it could force it into the wrong grid ref

Thanks for your reply! I’ll try that!

Tried adding 0.5, with the same results. I’ll try -0.5?

if its in the positives it needs to add.
if its in the negatives it needs to subtract.

Thank you all for taking your time. I think I’ve found an issue though,

You can see here that it should offset it by 3 studs but it gave an unrounded number once. Do you think this is part of the problem?

You can only be so accurate with numbers with a lot of decimal places. The computer has flaws in doing math with them

id make a 3d representation of a 3d grid. also compare the click position with the position its placed in. that way we can see where parts are falling out of place.

You could also change the transparency so you can see how much is overlapping

I don’t really understand as in what you want me to do with making a 3d representation. Sorry

so basically if you rounding to every multiple of 3, set a tiny block at every multiple of 3 in a little area. then you can clearly see it filling space. if it constantly places in the correct area then it works


I’ve tried putting tiny blocks, but that really messed some stuff up for some reason, is that normal?