How can I prevent Input position is {NaN, NaN, NaN} error?
Hi, I get this error ever so often but its not consistent so I cant tell whats causing it. After awhile or sometimes right away my player gets stuck and I get this rigidbody error:
rigidbody.position assign attempt for 'Man2(Clone)' is not valid. Input position is { NaN, NaN, NaN }. UnityEngine.Rigidbody:MovePosition(Vector3) SCR_character:UpdateMovementFixed() (at Assets/UAGK/Scripts/SCR_character.cs:263) SCR_character:FixedUpdate() (at Assets/UAGK/Scripts/SCR_character.cs:251)
Here is line 263:
GetComponent().MovePosition(new Vector3(GetComponent().transform.position.x,0f,GetComponent().transform.position.z)+(speed[0]*Time.deltaTime));
Is there a simple work around or how can I go about identifying the probllem?
Just a comment: It's inefficient call GetComponent() every time to get the transform. You should get it once (in Start() or something) and assign it to a member variable.
I'm sure you're trying to be helpful, but UA works best when comments are specific to the question. Otherwise (and this has happened) you get Q's where the useful info related to the Q is pushed to the second page.
But I just now moved this Q into the Help Room area (since it's about C#, not Unity.) The Help Room is basically a chat room, with lots of flailing around type Qs from beginners. It's fine to write just about anything there.
Answer by Owen-Reynolds · Aug 08, 2015 at 05:24 PM
NaN means "not a number" (look it up and check.) It means you made a mistake somewhere in your program and got a junk value. Often dividing by 0.
It's, obviously, contagious. So, your position is probably bad because something in the equation to make it is bad. I'd guess there's an error with your speed. Do the usual, add Debug lines, etc... to check it. Sometimes if you aren't moving, you can get funny errors with speed/facing.
Your answer
