I want so when player moves the part,he cant move it out of the plot
the issue is i have no idea how to do it and i need some tips
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?
LunarHandler:
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,
}
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:
Yes, especially if you want it to work no matter how the parts are rotated (although still at 90 degree intervals):
local DOT_TO_DIAGONAL = Vector3.xAxis:Dot((Vector3.xAxis + Vector3.yAxis + Vector3.zAxis).Unit)
--[[
Given a part and a world face (or a direction in world space, represented by a NormalId), return the face
of the part that most closely corresponds to that world face.
]]
function getPartFace(part: BasePart, worldFace: Enum.NormalId): Enum.NormalId
local worldNormal = Vector3.Fr…
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
system
(system)
Closed
March 31, 2023, 8:57pm
#8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.