I'm trying to see if a part faces another, i.e. a spotlight that detects when a player steps in front of it or something. I want this to work with rotating or rotated parts, and I was just wondering how I'd go about it.
while true do local pos = manipulator.Position + manipulator.CFrame:vectorToWorldSpace(subject.Position - manipulator.Position) local sides1 = manipulator.Position + manipulator.CFrame:vectorToWorldSpace(Vector3.new(manipulator.Size.x/2,manipulator.Size.y/2,manipulator.Size.z/2)) local sides2 = manipulator.Position - manipulator.CFrame:vectorToWorldSpace(Vector3.new(manipulator.Size.x/2,manipulator.Size.y/2,manipulator.Size.z/2)) if pos.x <= sides1.x and pos.x >= sides2.x and pos.y >= sides1.y and pos.z <= sides1.z and pos.z >= sides2.z then manipulator.BrickColor = BrickColor.new("Bright red") else manipulator.BrickColor = BrickColor.new("Really blue") end wait(0.1) end
this is what I've tried, and I realize it doesn't support rotation because I'm always checking to see if the position of the subject is greater than or equal particular sides, and when it rotates, then those sides are shifted. I want this to work with all rotations. Any tips?