Search Unity

Random.insideunitcircle is not starting at the origin 0,0;

Discussion in 'Scripting' started by calabi, Dec 9, 2018.

  1. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    I'm having weird inconsistent behaviour with this function.

    I have two objects using the Random.insideUnitCircle and they are behaving in different ways. I can offset one using this and it behaves perfectly. It starts at the origin x = 0, z = 0 so I can move it using the code below to where I want it.

    Code example below.

    Code (CSharp):
    1.  
    2.             Tempprefabpos = Random.insideUnitCircle * 5 + TemporiginPos;
    3.  
    4.             PrefabPos.x =  Tempprefabpos.x;
    5.             PrefabPos.y = 0;
    6.             PrefabPos.z =  Tempprefabpos.y;
    7.  
    8.             Instantiate(BusinessPrefab, PrefabPos, Quaternion.identity);
    But on another object the origin is offset from 0,0 somehow, which means it moves off in weird tangents that I dont want when I try to offset it from the origin. I'm wondering how this could happen and what could effect it. It seems like the values are correct when I watch them in the debugger, but somehow during instantiation, or I don't know when its moving them to the wrong position.

    I'm wondering if anyone has any idea of what could be happening because I cant figure it out. I dont think its anything wrong with the code but I dont know. Is another object affecting it somehow?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Your best bet is to use Debug.Log() and a small subset of all the objects you want to spawn, and just track down where the math is going wrong.
     
  3. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    Thanks, I think I've figured it out, it was going off the origin of the prefab object.
     
    Kurt-Dekker likes this.