How to get Object edges considering orientation

Hello everybody.

I’m making an object identification system outside a specified area through three-dimensional Vectors, I’ve been having problems identifying objects outside the area in which they have a rotation in which they make the object misaligned and thus occupy a space outside the area specified by the vector.

Below is a code example in which I am mentioning.

local Area = {
    Position = Vector3.new(50, 0, 80), -- Ignore the Y axis.
    Size = Vector3.new(100, 0, 100) -- Ignore the Y axis.
}

local Object = Instance.new('Part', workspace)
Object.Size = Vector3.new(10, 0, 10)
Object.Position = Vector3.new(5, 0, 0)
Object.Orientation = Vector3.new(0, 45, 0)

local XAxisEdge = Object.Position.X + Object.Size.X/2
print(XAxisEdge) 

--[[ The XAxisEdge variable does not handle the orientation, which means that it will not be possible to check if it is outside the area correctly. ]]

Thank you very much in advance! :grinning:

1 Like

Same thing as you wrote but for XAxisEdge you could get it relative to the object’s cframe like this:

local XAxisEdge = Object.CFrame:PointToWorldSpace(Vector3.new(Object.Size.X/2, 0, Object.Size.Z/2))

However this will return a vector3 value of that edge.

2 Likes
local XAxisEdge = Object.CFrame:PointToWorldSpace(Vector3.new(Object.Size.X/2, 0, Object.Size.Z/2))
1 Like