How do I make the placement system align with parts

Wait I fixed X axis just had to divide by two.

image

how do I determine the axis based on rotation? do you mean model rotation or raycast target?

1 Like

I have this code each frame:

local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.FilterDescendantsInstances = {CurrentModel} 

		local raycast = workspace:Raycast(
			Camera.CFrame.Position,
			(Mouse.Hit.Position - Camera.CFrame.Position) * 10,
			raycastParams)

		if raycast then
			local Pos = raycast.Position
			Pos = Vector3.new(
				math.floor(Pos.X / gridSize + 0.5) * gridSize,
				math.floor(Pos.Y / gridSize + 0.5) * gridSize,
				math.floor(Pos.Z / gridSize + 0.5) * gridSize
			)
			print("Yes6")
			local normal = raycast.Normal

			CurrentModel:PivotTo(CFrame.new((Pos + (normal * CurrentModel:GetExtentsSize().X/2)))*CFrame.Angles(0,math.rad(CurrentRotationY),0))
		end

it only aligns when the model is not rotated (CurrentRotationY) and only on X axis, how do I make a raycast system that is like this but no matter rotation.

So like, if mouse is on floor, the model offset ON floor, not in it. If it on wall, if ON wall, not in even if rotate.

1 Like

I got it to work by checking the raycasts Normal

local ray = workspace:Raycast(Camera.CFrame.Position, (Mouse.Hit.Position - Camera.CFrame.Position)*10, raycastParams)
		
		if ray then
			print(ray.Normal)
			if math.abs(ray.Normal.X) == 1 then
				Size = Size.X
			elseif math.abs(ray.Normal.Y) == 1 then
				Size = Size.Y
			elseif math.abs(ray.Normal.Z) == 1 then
				Size = Size.Z
			end
			CurrentModel:PivotTo(CFrame.new(ray.Position + ray.Normal*Size/2))
		end

how I found it

2 Likes

if you got it to work set your message as the solution so the post doesnt exist longer then it needs to

1 Like

I already did set a solution in the post

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.