How to get the side position of base part?

The part is a cuboid. I want to get position of sides as you can see on picture. I believe it requires some math but i have no idea how can I do that
image

its easy

X:
Part.Position + Vector3.new(Part.Size.X / 2, 0, 0)
Y:
Part.Position + Vector3.new(0, Part.Size.Y / 2, 0)
Z:
Part.Position + Vector3.new(0, 0, Part.Size.Z / 2)

( change + to - of you want the opposite thingy )

You need to use some CFrame magic to get the exact position of the middle of a side you want.
Something like this will work:

local part = -- BasePart

local function sidepos(part, face)
    local f = Enum.NormalId
    local neg = ("Back, Left, Bottom"):match(face.Name) and -1 or 1
    local c = part.CFrame
    local s = part.Size / 2
    if face == f.Top or face == f.Bottom then
        return c.UpVector * neg * s.Y
    elseif face == f.Right or face == f.Left then
        return c.RightVector * neg * s.X
    elseif face == f.Front or face == f.Back then
        return c.LookVector * neg * s.Z
    end
end
1 Like

doesn’t seems it worked?
image

doesn’t seems to be work
image

I don’t see any problem

local function GetSide(BasePart, Side : Enum.NormalId)
	if Side == Enum.NormalId.Front then
		return BasePart.Position + Vector3.new(BasePart.Size.X / 2, 0, 0)
	elseif Side == Enum.NormalId.Back then
		return BasePart.Position - Vector3.new(BasePart.Size.X / 2, 0, 0)
	elseif Side == Enum.NormalId.Left then
		return BasePart.Position + Vector3.new(0, 0, BasePart.Size.Z / 2)
	elseif Side == Enum.NormalId.Right then
		return BasePart.Position - Vector3.new(0, 0, BasePart.Size.Z / 2)
	elseif Side == Enum.NormalId.Top then
		return BasePart.Position + Vector3.new(0, BasePart.Size.Y / 2, 0)
	elseif Side == Enum.NormalId.Bottom then
		return BasePart.Position - Vector3.new(0, BasePart.Size.Y / 2, 0)
	end
end

-- example

for i, Side in pairs(Enum.NormalId:GetEnumItems()) do
	local Position = GetSide(workspace.Part, Side)
	
	local Part = Instance.new("Part")
	Part.Size = Vector3.new(1, 1, 1)
	Part.Position = Position
	Part.Anchored = true
	Part.CanCollide = false
	Part.Parent = workspace
end

This function assumes the part is unrotated, you need to multiply it by the LookVector, TopVector, or RightVector of the part’s CFrame to get the right position.