-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels