This is extremely confusing

Basically, I have this gray aiming part that is looking at the red brick, however the part must ALWAYS stay behind the transparent wall, no matter the size of the transparent wall too, I basically always want the part to be behind the transparent wall, while facing the red brick.
here’s what I got so far.

local target = workspace.Target
local lookatpart = workspace.AimPart
local hidebehind = workspace.HideBehindWall
lookatpart.CFrame = CFrame.lookAt(lookatpart.Position, target.Position)
lookatpart.CFrame = lookatpart.CFrame:ToWorldSpace(CFrame.new(0, 0, hidebehind.Size.Z / 2 + lookatpart.Size.Z / 2))	

on the Z axis it works perfectly fine, even with size changes from the transparent wall.
Screen Shot 2024-01-13 at 7.31.49 PM
Screen Shot 2024-01-13 at 7.32.10 PM

however, by changing the size of the transparent wall on the X axis, the gray aiming part’s position no longer is behind the transparent wall.
however on the X axis, it seems to be off.
Screen Shot 2024-01-13 at 7.33.38 PM

if anybody can provide any help, all would be appreciated. i’ve been stuck on this for a while now.

1 Like

Give this a try and see if it is closer to what you are after:

	local lookatpart = workspace.AimPart
	local hidebehind = workspace.HideBehindWall
	lookatpart.CFrame = CFrame.lookAt(hidebehind.Position, target.Position)
	lookatpart.CFrame = lookatpart.CFrame:ToWorldSpace(CFrame.new(0, 0, hidebehind.Size.Z / 2 + lookatpart.Size.Z / 2))

Turns out using Magnitude just works fine, but thanks for helping!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.