Rotating a building to a side of another building

So essentially for example I have a building like this image
and when I hover my mouse up against a wall I’d like it like this

I’ve been trying to figure out how’d I do it but I always seem to come to a dead end I’m wondering if mouse.hit needs to be used or ray casting
I do already have a placement system done I just need to get this rotation done.


Try this I dont remember the post I got it from but it uses ray casting to position the object on walls, but you have to use it on a model with a primary part that bounds the object completely

function placeAtMouse()
	-- make sure the mouse is pointing at something
	if mouse.Target then
		-- cast our ray and get our normal, which is a unit vector
		local unitRay  = workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y, 1) --origin,, -1, 0));
		local ray =, unitRay.Direction * 1000)
		local hit, pos, normal = game:GetService("Workspace"):FindPartOnRay(ray, moveModel); print (normal)
		moveModel:SetPrimaryPartCFrame(,pos+normal*15) * CFrame.Angles(-math.rad(90),0,0))
1 Like

Basically, this works by taking the surface normal (direction of surface) the ray lands on and offsetting the model in that direction.