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

Checking to see if any of the top surface of a part is facing a specified target?

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?

0
This math stuff confuses me. I would just use Raycasting to create a ray out of the particular side. ZeptixBlade 215 — 9y
0
That's not gonna work, as I've already explained last time I posted this answer. I'm trying to see if any of the part is facing another one. If I were to use rays, it would take about ten to twenty per stud to get an accurate result. aquathorn321 858 — 9y

Answer this question