Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by jaijai76 · Jun 17, 2014 at 11:12 AM · errornan

suddenly have 'nan, nan, nan' error

Iv been following etteski FPS tutorials and have had no problems so, but now im suddenly getting Nan errors even tho i only changed a non important thing i added into the script.

this is the 'mouseLookScript'

     var defaultCameraAngle : float = 60;
     @HideInInspector
     var currentTargetCameraAngle : float = 60;
     @HideInInspector
     var ratioZoom : float = 1;
     @HideInInspector
     var ratioZoomV : float;
     
     var clampDown = -70;
     var clampUp = 70;
      
     var ratioZoomSpeed : float = 0.2;
      
     var lookSensitivity : float = 5;
     @HideInInspector
     var yRotation : float;
     @HideInInspector
     var xRotation : float;
     @HideInInspector
     var currentYRotation : float;
     @HideInInspector
     var currentXRotation : float;
     @HideInInspector
     var yRotationV : float;
     @HideInInspector
     var xRotationV : float;
     var lookSmoothDamp : float = 0.1;
     @HideInInspector
     var currentAimRatio : float = 1;
     
     var headbobSpeed : float = 1;
     @HideInInspector
     var headbobStepCounter : float;
     var headbobAmountX : float = 1;
     var headbobAmountY : float = 1;
     @HideInInspector
     var parentLastPos : Vector3;
     var eyeHeightRatio : float = 0.9;
     
     function Awake ()
     {
         parentLastPos = transform.parent.position;
     }
      
     function Update () 
     {
         if (transform.parent.GetComponent(PlayerMovementScript).grounded)
             headbobStepCounter += Vector3.Distance(parentLastPos, transform.parent.position) * headbobSpeed;
         transform.localPosition.x = Mathf.Sin(headbobStepCounter) * headbobAmountX * currentAimRatio;
         transform.localPosition.y = (Mathf.Cos(headbobStepCounter * 2) * headbobAmountY * currentAimRatio) + (transform.parent.localScale.y * eyeHeightRatio) - (transform.parent.localScale.y / 2);
        
         parentLastPos = transform.parent.position;
      
         if (currentAimRatio == 1)
             ratioZoom = Mathf.SmoothDamp(ratioZoom, 1, ratioZoomV, ratioZoomSpeed);
         else
             ratioZoom = Mathf.SmoothDamp(ratioZoom, 0, ratioZoomV, ratioZoomSpeed);
            
         camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, ratioZoom);
      
         yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRatio;
         xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRatio;
        
         xRotation = Mathf.Clamp(xRotation, clampDown, clampUp);
        
         currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
         currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
        
         transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
     }

the only thing i changed was a variable i added called pause that meant when i pressed Esc i couldn't rotate my view, t worked perfectly no Nan errors but when i removed it i got Nan errors even tho it wasn't part of the original script and didnt effect the part giving me Nan errors.

I get this: !CompareApproximately (SqrMagnitude (q), 1.0F) UnityEngine.Quaternion:Euler(Single, Single, Single) MouseLookScript:Update() (at Assets/script/Player/MouseLookScript.js:69)

And this:transform.rotation assign attempt for 'playerCamera' is not valid. Input rotation is { NaN, NaN, NaN, NaN }. UnityEngine.Transform:set_rotation(Quaternion) MouseLookScript:Update() (at Assets/script/Player/MouseLookScript.js:69)

I also have errors with my player movement script because i use this for rotation.

If somebody could help me find out whats causing the errors and a way to fix that would be really helpful.

Edit: i tried copying and pasting directly from etteskis resources but still get the error even when i didn't before, i really don't know why it suddenly popped up.

FIXED: I think it was just a bug with unity, its a good engine but has a few weird bugs.

anyways, i fixed it by creating a new project and copying all files from old project, that's all. it was than fixed. I guess the error was just strangely caused when i edited the script (i hadn't edited that script in a while). It would be handy if these kinda bugs were fixed

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jun 17, 2014 at 10:35 AM 0
Share

NaN is often caused by a Divide By Zero situation.

playerCamera does not appear in the above script...

Is this script $$anonymous$$ouseLookScript??

avatar image jaijai76 · Jun 17, 2014 at 03:12 PM 0
Share

NaN is often caused by a Divide By Zero situation.

playerCamera does not appear in the above script... Is this script $$anonymous$$ouseLookScript?? sorry, i forgot to say, its in the mouselookscript, the mouselookscript controls the player camera tho, and the problem is is that it worked fine than i removed something that i added that wasnt in the tutorial than i got this error and cant see why

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ash_at_ReflexionHealth · Jun 17, 2014 at 05:43 PM

Check your parameters to SmoothDamp, it might use a division in there somewhere. Other than that, step line for line and see what the variables look like. The way nan works, once you get one it infects all the math you do after that, so if anything goes nan, everything that gets combined with it thereafter will be nan.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by AndreiMarian · Aug 17, 2017 at 09:41 AM

It has to do with the internals of Unity engine and Euler Angles.
Check this out for a better understanding of what's going on: https://forum.unity3d.com/threads/how-to-fix-quaternion-lookrotation-error.200686/#post-1359340

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unfixable Assets/Scripts/PlayerAttack.cs(30,15): error CS1525: Unexpected symbol `private' 1 Answer

Unity error "scripts exist in multiple locations" 1 Answer

dont work maxdistance 0 Answers

Transform.rotate returns NAN error. 0 Answers

Pause script errror. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges