How to do placement like in build a boat for treasure



how to do placement like in build a boat for treasure, not colliding into other parts

local blockView:Model=nil

function unequipped()
	if newUi then
		newUi:Destroy()
	end
	equipped=false
	if blockView then
		blockView:Destroy()
	end
end
function mouseRaycast(blacklist)
	local params=RaycastParams.new()
	params.FilterType=Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances=blacklist or {character}
	local ray=camera:ScreenPointToRay(mouse.X,mouse.Y)
	local raycast=workspace:Raycast(ray.Origin,ray.Direction*1000,params)
	return raycast
end

tool.Equipped:Connect(function()
	newUi=ui:Clone()
	newUi.Parent=plrUi
	equipped=true
end)
tool.Unequipped:Connect(unequipped)
humanoid.Died:Connect(unequipped)
character.Destroying:Connect(unequipped)

runService.RenderStepped:Connect(function()
	if equipped and blockView then
		local result=mouseRaycast({blockView,character})
		if result then
			local pos=CFrame.new(result.Position)
			pos+=Vector3.new(0,blockView.PrimaryPart.Size.Y/2,0)
			blockView:PivotTo(pos)
		end
	elseif equipped then
		blockView=blocks[selectedBlock]:Clone()
		blockView.Parent=camera
	end
end)```

You should put the code into a code block

--[[

```lua
-- Type the above and below lines, and then inbetween them, type your code. (although use 3 of the ` instead of 2 below, i used 2 because it would break)
`` 

]]

Normals.

You need to look at normals when raycasting.
I don’t really know how explain that but essentially position has to β€œbounce” off the surface upon raycasting and normals can be used for that.

You can use character escapes
Etc: ```

```

`\`\`

1 Like