There's more or less two ways to do this, and they both actually amount to the same thing.
What you have is sort of what it will look like, except that you wrote is just made up and not actually based on any of the math.
Math approach:
To determine to what extent a point is in a given direction, we use the Dot Product.
The direction we want is one part's lookVector
; the direction from one player to the other is the difference of their Position
s:
04 | forward = A.CFrame.lookVector |
05 | displacement = B.Position - A.Position |
07 | amountForward = forward:Dot(displacement) |
09 | if amountForward > 0 then |
Or, we can use the CFrame
and its Object Space.
Object space refers to using some object as the origin (so (0,5,0)
is 5 studs "up" where "up" is the top of a brick; (0,0,0)
would be the position of the brick rather than the origin)
1 | whereB = A.CFrame:pointToObjectSpace( B.Position ) |