Best way to detect if player is in a line with other players

I have tried many ways to achieve the solution but none of them is functional. What would be the best option to detect if a player is in a line that have other players (2+ players) next to him?

1 Like

Maybe the distance between the HumanoidRootParts

Maybe this answer would help:

I remember studying “collinear points” awhile back, maybe look into it.

A collinear point is essentially a point that lies on an imaginary or physical line from point A to point B.

I forgot the code, but it would / did require 3 parameters (a, b, c), and yes I had to port the code to Lua.

That’s a fantastic solution, but one small problem: the collinear is simulated in a 2D space (which only need the width and the height), but in my case I need to work in a 3D space, so do I have to just add Z into each pair of point in the formula?

edit: I’ll try this out later anyway I figured out that it only need X and Z, thanks for your help
edit2: thanks for the solution mate, worked like a charm!

No this is the point, unless you need the Y-axis of course, but for “forward, backwards, left, right” use the X and Z axis.

Probably a little off-topic:

I remember spending like 2 days studying collinear points, polygons, and trigonometry which this knowledge later came to use in a building system I’m making, it was really fun to learn and succeed, I love learning, and I love programming.

1 Like