[Unity3d] questions about Nan (not a number)

Source: Internet
Author: User

When the game is running, code that is unsafe to write is prone to Nan exceptions. Once Nan appears the entire game does not collapse also necrosis, the game is to be directly beat back the rhythm, is a development and testing personnel each have to buckle 3000 big bug.   General performance: 1.transform.rotation assign attempt for "XXX" are not valid. Input rotation is {nan, Nan, Nan, nan}.2.getting a error of Rigidbody.force assign attempt for ' XXX ' are not valid. Input position is {nan, Nan, nan}3.transform.localeulerangles assign attempt for ' XXX ' are not valid. Input Localeulerangles is {NaN, 0.000000, -0.000000}  anyway all kinds of similar, some not directly reported you wrong, indirectly to engage you to make you look for half a day.  nan is the letter meaning, not a number, is generally due to a count of 0 caused by, so if the design has to pay attention to ensure safety.   Some simple calculations can be better understood:  1/0 = NaN1 + nan = NaN2 * nan = nan  can say that any number involving the calculation of NaN will be directly assimilated, extremely powerful abilities Ah!   For example (C #): Float A = 1.0f;float B = 2.0f;float C = float. Nan; float result = A * B + c;//result is assimilated into Nan because C is Nan.   Encounters Nan can also throw exceptions to deal with, of course, assuming you know that there must be a Nan. Nan is not equal to any number, nor is it itself. So you can use Nan as a variable with your own judgment, if the return error is Nan, but these write the compiler will prompt you to have the stupid code, you can ignore it.   Example: x is Nan bool B_nan = (x = = x),  if (B_nan) Debug.Log ("X is a number."); ElseDebug.Log ("X is not a number!");   generally try to avoid the presence of this Nan.   in Unity3d, It is more likely to occur when the Time.timescale is 0, because in the game process, many operations are directly associated with Time.deltatime This parameter, once the Time.timescale is 0, then the value of Time.deltatime is 0. If you're not careful except it's not found, it Is the thing that is loved, haha.   If you want to implement a pause (pausing in a time.timescale way) and a part of something can move, consider yourself calculating a frame time interval. Of course this is likely to be the first frame of the time interval is particularly long. So you need to initialize this place, or directly calculate the F_deltatime value of the lost large.  float f_lastframerealtime; void Start () {f_lastframerealtime =  time.realtimesincestartup;}  void Update () {float f_deltatime = Time.realtimesincestartup-f_lastframerealtime;f_lastframerealtime =   Time.realtimesincestartup;}

[Unity3d] questions about Nan (not a number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.