Making part not go out of plot border

  1. I want so when player moves the part,he cant move it out of the plot

  2. the issue is i have no idea how to do it and i need some tips

  3. i was searching on devforum very long time but i couldnt find anything

player moves the part using handle arrows

Handles = script.Parent
local Part
local CF
local increment = 0.1
Handles.MouseButton1Down:connect(function()
	Part = Handles.Adornee
	CF = Part.CFrame
end)
Handles.MouseDrag:Connect(function(face, dist)
	local moving = Handles.Adornee
	local axi = {
		[Enum.NormalId.Right] = moving.CFrame.RightVector,
		[Enum.NormalId.Left] = -moving.CFrame.RightVector,
		[Enum.NormalId.Top] = moving.CFrame.UpVector, 
		[Enum.NormalId.Bottom] = -moving.CFrame.UpVector,
		[Enum.NormalId.Front] = moving.CFrame.LookVector,
		[Enum.NormalId.Back] = -moving.CFrame.LookVector,
	}
	moving.CFrame = CF + axi[face] * (math.floor(dist / increment) * increment)
end)

picture of the issue:

2 Likes

Can’t you just make a script that destroys the part if it touches the border?

Just FYI there’s also Vector3.FromNormalId, so you can replace all that with axis = Vector3.FromNormalid(face).

To fix your actual problem, you can check if the position where the object would end up is valid and then not move it unless that’s the case. Here’s a different response showing how you can check if one AABB is contained within another, which you could use for your check:

I dont really want it to destroy the part,just making it not move any further

You can get the X and Z position value for each border and then clamping the part’s X and Z position to the minimum and the maximum using math.clamp.

You have to check the corners of every part and then see if it’s outside of the border. The solutions here say just to check the part’s position and clamp it inside of the border but that’ll still allow the part to clip outside of it.

If you have rotating, I suggest checking all 8 corners and clamping them to prevent any clipping.

But how do i check if its inside the border or outside?

I dont really know how to put it inside the script

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