Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Checking to see if a part is facing another one? [UNSOLVED]

Asked by 9 years ago

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?

1 answer

Log in to vote
-2
Answered by 9 years ago

I think you can use Raycasting for that

0
That's really inefficient in this scenario, since I want to see if any of the top surface of the part is facing the subject aquathorn321 858 — 9y
Ad

Answer this question