Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a triangle shaped detection box?

I am making a security camera that can detect players. Currently I'm using a block and using the Touched event. Magnitude won't really work because I want the detection to be triangle shaped. Just wondering if there is a better way to do it, Thanks.

1 answer

Well a triangle is like a square, except the size of a line gets shorter or bigger depending upon the X value

So we could use a square detection box, which is fairly simple to implement, and use linear interpolation: (b - a) * c + a, where b is the max, a is the min, and c is a number between 0 and 1. Since the min will always be zero since one end is pointed, the equation simplifies to bc.

You would check if a player part is inside the square. Then, calculate c using the part X, and the minX and maxX positions of the triangle. Then, use the linear interpolation thing to calculate minY and maxY. Then, if the partMaxY < maxY and partMinY > minY, that probably means the part is inside the triangle.

P.S. idk if this actually works, i would test it but it's 10 pm and i need to sleep

This discussion is preserved as it was. New answers, comments, and votes are closed.