How would I make this part always behind this part no matter what size or direction?

This might sound confusing, but I want this red part to always be behind the transparent blue part, no matter what size or rotation.
I’ve tried doing something like

redpart.CFrame = bluepart.CFrame * CFrame.new(0,0,2.5)	

however that will always make the red part 2.5 studs away from the blue part, rather than being always behind the blue part. for example:
Screen Shot 2024-01-13 at 5.14.47 PM
blue part is (5,5,5) in size, while red part is always behind it.
Screen Shot 2024-01-13 at 5.15.53 PM
blue part is (10,5,5), in size, while red part is still behind it.

if anybody can help me, all will be appreciated.

1 Like
local BluePart = script.Parent.Part
local RedPart = script.Parent

local Offset = CFrame.new(0, 0, BluePart.Size.Z / 2 + RedPart.Size.Z / 2)

BluePart:GetPropertyChangedSignal("CFrame"):Connect(function()
	RedPart.CFrame = BluePart.CFrame:ToWorldSpace(Offset)
end)

Wait whoops I read that wrong

1 Like

Here you can add a - to lookvector so it behind

local bluepart =…
local redpart = …

while wait() do
redpart.Position = bluepart.Position+bluepart.CFrame.LookVector*(bluepart.Size.Z/2)
end

1 Like

Sorry I might of made this sound alot simplier than it is, What I’m making is an NPC who will take cover and find a wall to go behind, im placing a wall and making a script check if the wall is good enough to hide behind.
Screen Shot 2024-01-13 at 5.28.01 PM
the parts you see behind the transparent wall facing the large brick determines if the wall is good enough to hide behind.

however on the X axis


the part isn’t behind the wall. how would i make it be behind the wall at all times no matter what axis?

Also the parts behind the wall are always facing towards the gray brick you see infront of the transparent wall. just said this to make it more clearer if your wondering why the rotation seems a bit weird for the parts behind the transparent wall.

Can you send us your current code and explain directly what you need? I don’t understand! @leuasde1 has given a solution to the original problem proposed - please explain it!