Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] How do you make part face snapping?

So I have this extremely simple part (and model) placing script thats skeleton looks something like this...

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local model = game.ServerStorage.Model

local build = false

function startBuilding()
	build = true
	local obj = model:Clone()
	while build do
		wait()
		model:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.) * whatever_rotation_angle)
	end
end

mouse.Button1Down:Connect(function()
	if not building then
		startBuilding()
	else
		building = false
	end
end)

Very simple, but the issue with it is that when the mouse.Target has an object in it, the mouse.Hit.p gets a bit skewed and ends up placing the model a bit higher up and inside of the mouse's target.

Example 1

Example 2

The desired behavior I want is for when mouse.Target has an Instance, then snap to the mouse.TargetSurface regardless of the rotation of the model.

How would I offset the model so that it sort of snaps to the face of the mouse's target?

Edit: I was able to get the height to snap in this example, but I still don't know how to snap the X and Z according to the side face.

Height Snapping Example

5 comments

0

CanColide makes the object unable to go through each other and Anchored makes it stay still (you should know already). Without Anchored and CanColide, it will (might) go through each other and maybe get fling around the map.

0

CanCollide doesn't matter with CFrames, and if I used Position then it would appear on top of the mouse.Target.

0

There's also a property of a BasePart called Surface (I forgot) which IDK what it does.

0

The mouse.TargetSurface (like I mentioned in my post) returns values 0-5 (surfaces), but you can't use them for position. The part surfaces are just strings, so you can't use those either.

0

Or you could manually face snap it yourself (but it wouldn't look so great). Other than that, I do not know any other ways.

1 answer

Ended up doing it by taking the mouse.TargetSurface values and specifically offsetting the model to whatever the surface was.

Solution

This discussion is preserved as it was. New answers, comments, and votes are closed.