I have been using a combination of ray casts coming from the player and dots to tell which side of a cube the player is against. I do not need how much to the right or how far forward the player is all I need is whether they are on the right, left, front, or back side of the cube.
I’ve been using this code and had been working pretty well.
wall = hit.transform;
Vector3 hitLoc = wall.InverseTransformPoint(hit.point);
Vector3 hitDir = hitLoc.normalized;
dotF = Vector3.Dot(wall.TransformDirection(Vector3.forward).normalized, hitDir);
dotR = Vector3.Dot(wall.TransformDirection(Vector3.right).normalized, hitDir);
if (Mathf.Abs(dotF) > Mathf.Abs(dotR))
{
dotR = 0.0f;
if (dotF > 0)
{
dotF = 1.0f;
}
else if (dotF < 0)
{
dotF = -1.0f;
}
}
if (Mathf.Abs(dotR) > Mathf.Abs(dotF))
{
dotF = 0.0f;
if (dotR > 0)
{
dotR = 1.0f;
}
else if (dotR < 0)
{
dotR = -1.0f;
}
}
However once I started using cubes that were rotated I started having problems. Anytime the player nears the edges of the cubes it will switch to say that it is on another side.
Example: If the player is on the front side of a cube that is rotated 165 on the y axis and moves toward the edge then it suddenly says the player is on the right side.
I’m no expert when it comes to this kind of stuff, and can’t figure out how to make it work. Maybe dots were the wrong way to go. As long as I can tell which side of the cube the player is against I don’t care what method is used, so any suggestions are welcome. Thanks.