Hello,
I’m trying to check if 3 points in a 3D space are collinear. I chose to make 2 Vector3 AB and BC and check if the cross-product of the two equals Vector3.zero. However, it’s not working. When I have a point in the top plane in position A2, one in the middle plane in B2 and one in the bottom plane in A2, it considers as if the points were collinear. Here is my code:
int score = 0;
for (int i = 0; i < playerSlots.Count - 1; i++)
{
for (int j = i + 1; j < playerSlots.Count - 1; j++)
{
if (Vector3.Cross(playerSlots[j] - playerSlots[i], playerSlots[playerSlots.Count - 1] - playerSlots[j]) == Vector3.zero)
{
score++;
Debug.Log("score");
}
}
}
Where playerSlots.Count are all the points the player put on the game.
Can anyone help me? I can provide more information if needed. Also, if there is a better way to do this, please tell me.
Thanks!