Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

infinity or nan floating point numbers appear when calculating matrices for collider

Discussion in 'Scripting' started by Keemo, Apr 12, 2015.

  1. Keemo

    Keemo

    Joined:
    Apr 22, 2014
    Posts:
    31
    Hello everyone,

    im working on a multiplayer game where the server spawns for every player on the server a gameobject. ( A Vehicle which can be controlled by a player). This works, but sometimes especially when there are more players on the server, the clients get the following error message:

    "infinity or nan floating point numbers appear when calculating matrices for collider"

    When this error message appears, every spawned vehicle gets somehow invisible. I can still see them getting moved by clients on the server, but the clients just dont see them anymore.

    This line is the line which throws the error :
    Code (csharp):
    1. transform.position = Vector3.Lerp(transform.position, wantedpos, 2);
    Im very confused and hope that someone can explain me whats going on.

    Btw. I spawn the Vehicles with Network.Instantiate and the clients never delete them. They should always be there.
     
  2. Keemo

    Keemo

    Joined:
    Apr 22, 2014
    Posts:
    31
    Fixed it!

    It was because the wantedpos values were for a short amount of time NaN. (NaN* something = NaN)

    Code (csharp):
    1.  
    2. if (!float.IsNaN(wantedpos.x) && !float.IsNaN(wantedpos.y) && !float.IsNaN(wantedpos.z))
    3.                     {
    4.                         transform.position = Vector3.Lerp(transform.position, wantedpos, 2);
    5.                     }
    6.  
     
  3. mcapousek

    mcapousek

    Joined:
    Jan 11, 2013
    Posts:
    9
    See 'Vector3.Lerp' documentation... especially for the 3rd parameter! I think that "constant" isn't "right" choice :)