Get part behind another part

Pretty self explanatory trying to get the part behind and in front of another part, regardless of x and z axis…

Raycasting seems like a good start

Property Description
RaycastResult.Instance The BasePart or Terrain cell that the ray intersected.

Misread the question, oops.
Like @Juicy_Fruit said use raycasting to achieve this.

they aren’t trying to position a part behind another part, look at what @Juicy_Fruit said

Um can you explain bit better What do you meant by

–Trying to get the part behind and in front of another part

bit confusing

as far i can understand it

here is a sample of code


local Part1--Gets InFront of Part3
local Part2--Gets behind of part3
local Part3--The Part where you positons the parts

--Moves to Place
Part1.CFrame = Part3.CFrame
Part2.CFrame = Part3.CFrame

--Goes to Positions
--Goes Foward
Part1.Positon += Vector3.new(0,0,0)--Write the length of part3 on one of the zeros not sure what 0 is it

--You Could Do same for part2

Not to me! Could you go into detail about what you’re asking, and give an example?

I don’t think ray casting is the right answer, but I’m not sure what the question is!

I want to know which part is in front of behind part A, regardless of X and Z axis

When you rotate a part In Cframes X becomes Z and vice versa

I.e.

A.

                    C

     B

C is “in front” of B and A is behind it, hope I’ve provided enough reassuring information / insight on what I seek to achieve.

I use this for my combat scripts, perhaps this may help you.

local vector = humanoidroot2.Position - humanoidroot1.Position
if vector:Dot( humanoidroot1.CFrame.lookVector ) > 0 then
    -- humanoidroot2 is in front of humanoidroot1
end