If the camera is pointed EXACTLY upwards or downwards, such that direction == Vector3(0,1,0) or Vector3(0,-1,0) then the projection will fail and the interpolation matrix is filled with NaN values.
This happens because of the following line of code:
|
Vector3 xaxis = Vector3.Cross(up, zaxis).normalized; |
This should become the following code:
Vector3 zaxis = (position - target).normalized;
Vector3 xaxis = Vector3.Cross(up, zaxis).normalized;
if (Mathf.Approximately(xaxis.magnitude, 0f))
{
up = Vector3.right;
xaxis = Vector3.Cross(up, zaxis).normalized;
if (Mathf.Approximately(xaxis.magnitude, 0f))
{
up = Vector3.forward;
xaxis = Vector3.Cross(up, zaxis).normalized;
}
}
Vector3 yaxis = Vector3.Cross(zaxis, xaxis);
Basically, if the cross of zaxis and up is a zero vector, then pick right arbitrarily. If THAT is still somehow 0, then pick forward. The extra check to forward isn't really necessary but it's the standard pattern for LookAt.
If the camera is pointed EXACTLY upwards or downwards, such that direction ==
Vector3(0,1,0)orVector3(0,-1,0)then the projection will fail and the interpolation matrix is filled with NaN values.This happens because of the following line of code:
Brunetons-Ocean/Assets/BrunetonsOcean/Scripts/Projection.cs
Line 353 in e764ccb
This should become the following code:
Basically, if the cross of zaxis and up is a zero vector, then pick right arbitrarily. If THAT is still somehow 0, then pick forward. The extra check to forward isn't really necessary but it's the standard pattern for LookAt.