NAN showing up

No idea how i can be getting NAN on DistanceFromTarget inside LateUpdate.
Totally lost.

    public float DistanceFromTarget = 7.5f;

    Transform pet;



    private void Start(){

        pet = PhotonNetwork.Instantiate(MyFunctions.FirstLetterToUpper(GameSettings.UserData["class"].Value+" Pet"),gameObject.transform.position,new Quaternion(90,162.8f,0,0),0).transform;
    }







    private void LateUpdate(){


        if(pet) {
            Debug.Log(DistanceFromTarget);
            pet.position = transform.position + new Vector3(DistanceFromTarget,0,DistanceFromTarget);
        }




    }

You should do a NaN check, by using “float.IsNaN” which you can read more about here in this useful answers post: float.IsNaN(value) returns true if the value is a NaN.

And perhaps if the value is NaN, then do some direct assignment to the last known “good” value, until it becomes not NaN. (Yeah that’s technically a double negative haha)

another wierd issue though.

if I do
pet.rotation = new Quaternion(90,0,0,0);

It assigns 180.
If i use 45 it assigns 180
if i use 0 it assigns 0.

Have you tried using

pet.transform.eulerAngles = new Vector3 ( 90, 0, 0);

Or alternatively you could try:

pet.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0));

Quaternions don’t work this way, you’ll be better off using Euler angles as suggested above :slight_smile:
On this site you can calaculate angles ↔ quaternions and see how they work.

Also it is normal to have “different” angles collapsing to same Quaternion.