Make placement system stick to surfaces

  1. What do you want to achieve? Keep it simple and clear!

Basically im making a placement system.

  1. What is the issue? Include screenshots / videos if possible!

I need the system to be able to stick to different surfaces if that makes any sense. Atm you can move the objects in a grid but you cant build on top of other blocks :frowning:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Some years ago when i didnt know about Object/World space i used to have this line of code in my systems:

local S = {
	[Enum.NormalId.Top] =,1,0),
	[Enum.NormalId.Bottom] =,-1,0),
	[Enum.NormalId.Left] =,0,0),
	[Enum.NormalId.Right] =,0,0),
	[Enum.NormalId.Front] =,0,1),
	[Enum.NormalId.Back] =,0,-1)

local Surface = S[Mouse.TargetSurface],0,0) + (Surface * (Object.PrimaryPart.Size*.5))

I tried that with my new system which converts the Mouse position to object space. But it just doesnt work very well.

Anu help would be really cool since ive ran into a wall and dont know how to fix this issue.

Heres a vid showcasing the issue(As you can see from the video. I cant place cubes on different surfaces in this case the top)

And heres also the code i use in my placement system

local function Convert(CF,S)

	if Mouse.Target ~= nil then
		Mouse.TargetFilter = Object
		local Rel = Plot.CFrame:ToObjectSpace(Mouse.Hit)
		local Grid = Convert(Rel,Object.PrimaryPart.Size)

Could please add some prints of the values set so we can help you more.

1 Like

What do you mean by “prints of the values”?

Print out value of Rel and Grid and the PlotCframe before and after doing the Pivot.

Alr sure?

Relative CF

Grid CFf

Plot CF

Would you please print out the plot CF value before and after it is set.
as in
print(“plot before=”,Plot.CFrame) before its changed
print(“plot after=”,Plot.CFrame) after

instead of using Mouse.Hit, use raycasting. And don’t use Mouse.Move as your object’s position won’t update if you move your character without moving your mouse.