- Home /
Confusing error messages, !IsNormalized and NxRay direction not valid
I am getting weird errors from my script, I do not understand why. I have looked up these errors but I can't find anyone who has gotten it for the same reason. Most other people have gotten the errors from lens flares on their cameras which I don't understand. The errors are:
NxRay direction not valid: must be unit vector. UnityEngine.Physics:Linecast(Vector3, Vector3, Int32)
!IsNormalized (ray.GetDirection ()) UnityEngine.Physics:Linecast(Vector3, Vector3, Int32)
!IsNormalized (dir)
This is the bit of code it is from I have commented on the line of the error.
void Cover()
{
Vector3[] covers = new Vector3[100];
List<Vector3> potential = new List<Vector3>();
NavMeshHit navhit;
for(int i = 0; i < covers.Length - 1 ; i++)
{
NavMesh.FindClosestEdge(transform.position + Random.insideUnitSphere * 5, out navhit, passableMask:1);
covers[i] = navhit.position;
if(Physics.Linecast(navhit.position, sensors.eyes.playerPosition, ~mask) ) // Error happens on this line
{
potential.Add(covers[i]);
}
}
if(!hascoverpos)
{
hascoverpos = true;
chosen = potential[0];
}
if(!Physics.Linecast(chosen, sensors.eyes.playerPosition, ~mask) )
{
Debug.Log ("Recalculating...");
hascoverpos = false;
}
print("Potential Covers = " + potential.Count);
print("All Covers = " + covers.Length);
TargetDestination = chosen;
}
Can anyone help me? thanks
I should add that as far as I know the script seems to work, I can't see what's going wrong.
The errors are all saying the same thing. There is a direction vector and it's length is not 1. Since it happens on your line 13, my guess is that the start
and end
values you pass into Linecast
do not make a direction, possibly because they have the same value, or one of the vectors is invalid in some way. If both vectors were valid, then Unity and/or PhysX ought to be able to make a direction vector from end-start and then normalise it.
The errors happen on lines 13 and 25, they both are pretty much the same thing, linecasts
Thank you Graham I will try to see where the two points are and check if they have the same value
Your answer
Follow this Question
Related Questions
Run-Time Errors! Particle Instantiations 1 Answer
Help with script 1 Answer
How to fix !IsNormalized (dir) error 2 Answers
Can't add script to anything error 1 Answer
raycast error 1 Answer