I have been trying to work out how to check if a point is on the same line and inbetween two other points. It seems to work if the line is diagonal but if its straight vertically or horizontally it fails.
This is my method:
public bool isBetween(Vector3 C, Vector3 A, Vector3 B)
{
Vector3 sum = Vector3.Cross(A,B) + Vector3.Cross(A,C) + Vector3.Cross(B,C);
if (sum.x == 0 && sum.z == 0 && sum.y == 0)
{
Vector3 min = Vector3.Min(A, B);
Vector3 max = Vector3.Max(A, B);
// only checking 2 dimensions
if (C.x > min.x && C.x < max.x && C.z > min.z && C.z < max.z)
{
return true;
}
}
return false;
}
It works for certain cases but not 100% for all cases. Not sure how to fix it to get it working.